![]() |
| | #1 |
| Registered User Join Date: Nov 2009
Posts: 2
| Simple struct definition error I have defined the Console struct as follows... Code: typedef struct
{
//console properties
int Number;
void (*Hide)(Console *);
void (*Show)(Console *);
short x;
short y;
short width;
short height;
} Console;
"Line 5: Expected ')' before '*' token" That is on the Hide function pointer line next to the last * star thing (@ char 23). I don't understand why, I thought that's how to define a function pointer in a struct that takes a pointer as an argument. If it makes any difference, this is going to be a program for a TI89 calculator. Thanks |
| hotwheelharry is offline | |
| | #2 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,639
| You can't use Console * inside the structure that defines Console in the first place. You need to typedef it first. Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #3 |
| Registered User Join Date: Nov 2009
Posts: 2
| like... Code: typedef Console* ConsoleRef;
typedef struct
{
//console properties
int Number;
void (*Hide)(ConsoleRef);
void (*Show)(ConsoleRef);
short x;
short y;
short width;
short height;
} Console;
Last edited by hotwheelharry; 11-06-2009 at 09:04 PM. |
| hotwheelharry is offline | |
| | #4 | |
| Registered User Join Date: Nov 2008
Posts: 75
| Quote:
And the first typedef doesn't work. An example that works: Code: #include <stdio.h>
struct console;
typedef struct console *console_ptr;
typedef struct console {
int a;
console_ptr c_p;
} console;
int main(void)
{
console c = {.a = 0, .c_p = NULL,};
printf("c.a = %d\n", c.a);
return 0;
}
Last edited by MisterIO; 11-06-2009 at 09:50 PM. | |
| MisterIO is offline | |
| | #5 |
| Registered User Join Date: Jun 2008
Posts: 1,276
| Code: typedef struct myConsole
{
...
struct myConsole* cpointer;
...
} Console;
In case you are wondering, you cannot replace above "struct myConsole*" with "Console*" inside the struct, cause it has not yet beend typedef. |
| C_ntua is offline | |
| | #6 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,783
| Please don't typedef pointers like this. They obfuscate the code! Is it really that difficult to type out the * to make it a pointer type?
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #7 |
| Registered User Join Date: Nov 2008
Posts: 75
| IMO there's no point in doing the typedef of struct console either, unless he wants to create an opaque type(which wouldn't make it necessary, but sometimes it's used). |
| MisterIO is offline | |
| | #8 | |
| critical genius Join Date: Jul 2008 Location: SE Queens
Posts: 5,172
| Quote:
Code: typdef struct console; struct console; | |
| MK27 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Testing some code, lots of errors... | Sparrowhawk | C Programming | 48 | 12-15-2008 04:09 AM |
| failure to import external C libraries in C++ project | nocturna_gr | C++ Programming | 3 | 12-02-2007 03:49 PM |
| using c++ in c code | hannibar | C Programming | 17 | 10-28-2005 09:09 PM |
| ras.h errors | Trent_Easton | Windows Programming | 8 | 07-15-2005 10:52 PM |
| Linking error | DockyD | C++ Programming | 10 | 01-20-2003 05:27 AM |