I am trying to pass a pointer by reference to a function and get that function to point my pointer at a structure that it finds.
char get_structure(STRUCTURE **ptr) { if(foundstructure) { *ptr = &theStructure; return 1; } return 0; }
This works how I expect it, but when I try and declare the function prototype in the header file:
char get_structure(STRUCTURE **ptr);
I always get a compiler error:
error C141: syntax error near '*', expected ')'
I don't get an error when this is a defined type like char, int or long, but I get the error when this is a pointer to a typedef that I have defined.
How can I declare this in my header file without an error?
Nathan
In that case, you'd still to have to give them something to try!
Specifically, You'd have to give them a minimal but complete example that demonstrates the issue. You should be able to do that with non-confidential code. And you could share that on the foum.
I know it's not the structure that is the problem. This structure has been used in it's current state for over a year now in many implementations. It is only the double pointer in the prototype that is causing grief.
Actually, no, it's not. If you put that exact code into (minus the syntax error '...', and plus a typedef for uint8) into an empty file, and compile that, it works just fine and dandy (uV4, C51 9.02). Which goes to show that whatever the problem actually is, it's not what you claim it is.
So, next try: show an actual, self-contained example that demonstrates the error.
I would like someone from Keil to try this however
if so, you are in the wrong place, Keil support does not monitor the forum
contact Keil support directly
I can't post source code, because it would void my non-disclosure contract, but here's a post safe version:
Header file:
#define STRUCT_LEN 12 typedef union _STRUCTURE { unsigned char bytes[STRUCT_LEN]; struct _STRUCT1 { unsigned long field1; unsigned char field2; unsigned char field3; unsigned char field4; unsigned char field5; unsigned char field6[4]; } STRUCT1; struct _STRUCT2 { unsigned long field1; unsigned char field2; unsigned char field3; unsigned char field4; unsigned char field5; unsigned char field6; unsigned char field7; unsigned char field8; unsigned char field9; } STRUCT2; ... } STRUCTURE; uint8 function(STRUCTURE **ptr); //This is causing compile error C141
C file:
uint8 function(STRUCTURE **ptr) { if(...) { *ptr = &structure; return TRUE; } else return FALSE; }
I know it's not the structure that is the problem. This structure has been used in it's current state for over a year now in many implementations. It is only the double pointer in the prototype that is causing grief. I'm going to go with the void work around.
uint8 function(void **ptr) { if(...) { *ptr = (void *)(&structure); return TRUE; } else return FALSE; } uint8 function(void **ptr);
I would like someone from Keil to try this however. I am sure that there is a problem that should be fixed here.
How is this a problem with my structure? how can we tell when you do not show it.
I think you are getting too few errors rather than too many
"more words do not make you appear stupid they make you appear clear"
Erik
How is this a problem with my structure? I've already made is clear that my code is executing and working fabulously. It is ONLY the function prototype that is having issues. The actual function declaration does not return any error. And using a single pointer returns no error. It is only the double pointer in the prototype declaration that returns an error.
Which makes it look more like a problem with your definition of STRUCTURE.
Again, you're going to have to show a complete example for anyone to be able to help you with that...
Void works just find as well.
<quote> "That does happen to the best of us" </quote>
Yes indeed. It is proberbly hard for you to believe this but once it even happened to me.
But as I tell my team 'the only of you who doesnt make mistakes is the one who does nothing'.
Always yo're freind.
Zeusti.
Absolutely. See this thread - nobody believed me at the beginning, until it was confirmed and fixed...
http://www.keil.com/forum/19955/
am trying to pass a pointer by reference to a function and get that function to point my pointer at a structure that it finds.
char get_structure(STRUCTURE **ptr)
are you one of those "C is C whatever it runs on" types?
if you look at the C51 assembler the above will generate, you will realize that "C is C whatever it runs on" is a very bad mantra when working with this architecture. There is absolutely nothing wrong with programming the '51 in C (I have, probably, written 100,000 lines of it) but do think of the architecture when designing the code.
The process of creating an example which illustrates the problem - and only the problem - certainly can focus the mind and bring the solution to light all by itself!
http://www.keil.com/forum/15346/
"That does happen to the best of us"
Indeed it does!
See: www.8052.com/.../100837
You really will have to show a complete example demonstrating this. Without actually seeing how you defined STRUCTURE, there's no way anyone can help you. I'll venture a guess though: STRUCTURE is not actually a typedef, it's a #define, and therein lies your problem.
And don't be too embarrassed if, while composing that example. the cause of the problem jusmps out at you and you feel tempted to yell at yourself "How could you possibly overlook that, stupid!" That does happen to the best of us.
char get_structure( void **ptr );
... and some casting...?
View all questions in Keil forum