CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Passing structure problem!! It's BuG?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
micman
Guest







Passing structure problem!! It's BuG?
PostPosted: Mon May 10, 2004 6:16 am     Reply with quote

Hi all,
I have problem with passing structure at the function,example code:
#include "C:\5\ffv.h"
#int_RTCC
RTCC_isr()
{

}
void main()
{
struct sgara gara;
port_b_pullups(TRUE);
setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,255,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_ccp1(CCP_PWM);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);

gara.mt = 50;
intet(&gara);
}

void intet(struct sgara gara){
int8 mt1;
int8 *ptr;
ptr = (int8 *)gara; //ptr = 0x4517
mt1 = gara.mt;
intet1(&gara);
}

void intet1(struct sgara gara){
int8 mt1;
int8 *ptr;
ptr = (int8 *)gara; //PROBLEM!!!!!! it's bug? ptr = 0x4918
mt1 = gara.mt; // error passing!!! mt1 = 18
intet2(&gara);
}

void intet2(struct sgara gara){
int8 mt1;
int8 *ptr;
ptr = (int8 *)gara; //ptr = 0x3211
mt1 = gara.mt; //mt1 = 1c
intet3(&gara);
}
void intet3(struct sgara gara){
int8 mt1;
int8 *ptr;
ptr = (int8 *)gara; //ptr = 0x4520
mt1 = gara.mt; //mt1 = 0x20

}

//---------------------------------------------------------------
//File header


#include <18F452.h>
#device ICD=TRUE
#device adc=8
#use delay(clock=20000000)
#fuses NOWDT,WDT128,HS, NOPROTECT, NOOSCSEN, BROWNOUT, BORV42, PUT, STVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)


//Strutture
struct sgara {
int8 mt;
};

void intet(struct sgara gara);
void intet1(struct sgara gara);
void intet2(struct sgara gara);
void intet3(struct sgara gara);
mvaraujo



Joined: 20 Feb 2004
Posts: 59
Location: Brazil

View user's profile Send private message

PostPosted: Mon May 10, 2004 7:21 am     Reply with quote

Let me ask you this: Is it necessary for you to pass the structure?
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Mon May 10, 2004 7:38 am     Reply with quote

Instead of passing the structure, pass a pointer to the structure. It's more effecient that way.
Ttelmah
Guest







PostPosted: Mon May 10, 2004 7:51 am     Reply with quote

Darren Rook wrote:
Instead of passing the structure, pass a pointer to the structure. It's more effecient that way.

This is actually, where he is going wrong!.
He is passing a pointer, but has declared in the subroutine that he is passing the actual structure...
The two statements involved are:

intet(&gara);

in main, and:

void intet(struct sgara gara){

The first says 'pass the address of this structure', while the second tells the routine to expect the structure itself. The code needs to either be changed to pass the structure, or to expect the pointer...

Best Wishes
micman
Guest







PostPosted: Mon May 10, 2004 7:58 am     Reply with quote

as I can change the code for passisng the structure o the pointer at the structure?
Thanks
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon May 10, 2004 5:25 pm     Reply with quote

Sure. For example, your first function should look like this:

Quote:

void intet(struct sgara * gara){
int8 mt1;
int8 *ptr;
ptr = (int8 *)gara; //ptr = 0x4517
mt1 = gara->mt;
intet1(gara);
}
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Mon May 10, 2004 6:37 pm     Reply with quote

Ttelmah wrote:
This is actually, where he is going wrong!.


Oops. Embarassed
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group