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

structure error

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



Joined: 30 Mar 2010
Posts: 3

View user's profile Send private message

structure error
PostPosted: Mon Apr 19, 2010 5:02 am     Reply with quote

Hello,

I have a structure argument for a function.
For example:
Code:

struct pulsstruct {  int8 channel;
                     int32 delay;
                     int32 pulsewidth;};

main {
struct pulsstruct puls, *pptr;
pptr=&puls;
savevalues(pptr);
}

void savevalues(struct pulsstruct *);

void savevalues(struct pulsstruct *pptr) {
   int8 value;
   value=pptr->channel;
}

The compiler doesn't like this:
Quote:
Expecting a structure/union

Whats wrong?
Thanks for any help.

wolfgang
draghi



Joined: 01 Apr 2010
Posts: 2

View user's profile Send private message

PostPosted: Mon Apr 19, 2010 8:42 am     Reply with quote

Try to typedef the structure first and than declare the variables of this type.
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Mon Apr 19, 2010 8:47 am     Reply with quote

The prototype defintion, needs the matching variable name.
In CCS, the prototypes must be _identical_ to the real defintions....

Best Wishes
sailor0815



Joined: 30 Mar 2010
Posts: 3

View user's profile Send private message

PostPosted: Wed Apr 21, 2010 12:39 am     Reply with quote

Hello,

I've changed, but same error.
any other hint?

thanks in advance

wolfgang

struct pulsstruct { int8 channel;
int32 delay;
int32 pulsewidth;};

main {
struct pulsstruct puls, *pptr;
pptr=&puls;
savevalues(pptr);
}

void savevalues(struct pulsstruct *pptr);

void savevalues(struct pulsstruct *pptr) {
int8 value;
value=pptr->channel;
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 21, 2010 12:52 am     Reply with quote

Quote:
main {
struct pulsstruct puls, *pptr;
pptr=&puls;
savevalues(pptr);
}

How should the main function (or any function) be written in a C
program ? What characters are used to delimit the parameter field ?
I recommend that you get a book called "The C Programming Language".
You need to know the basics before attempting to use CCS.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Apr 21, 2010 2:09 am     Reply with quote

As PCM programmer showed, you need to learn some basics and one of them for standard C is the prototype for the function needs to be BEFORE it is used.

Where is the first place you call savevalues ?
Answer, in main.

Where have you placed your prototype ?
Answer, after main.

So when the compiler gets to the function call savevalues in main it will have no idea what it is supposed to be and will fail with an error, I am not sure this is the error you are seeing and yes it would be easy for me to test but ...

Put your function prototype before main but after the struct definition other wise the compiler may complain that it doesn't know what pulsstruct is.
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