View previous topic :: View next topic |
Author |
Message |
sailor0815
Joined: 30 Mar 2010 Posts: 3
|
structure error |
Posted: Mon Apr 19, 2010 5:02 am |
|
|
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
|
|
Posted: Mon Apr 19, 2010 8:42 am |
|
|
Try to typedef the structure first and than declare the variables of this type. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Mon Apr 19, 2010 8:47 am |
|
|
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
|
|
Posted: Wed Apr 21, 2010 12:39 am |
|
|
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
|
|
Posted: Wed Apr 21, 2010 12:52 am |
|
|
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
|
|
Posted: Wed Apr 21, 2010 2:09 am |
|
|
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. |
|
|
|