Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wanting2learn

macrumors newbie
Original poster
Aug 19, 2010
13
0
Hi,

I'm a c/c++ developer and I'm new to iPhone programming.

I'm trying to convert a program to iPhone and wish to use existing code where possible. I have the following problem:

In a header file I have the following:

Code:
typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef unsigned int UINT;


typedef struct tagMSG_VIRTUAL{
	DWORD	dwType;			// message type 
	WORD	wVersion;		// the version number for the message. Filled in by the derived(or real) message
	WORD	wReserve2;		// Reserve1	
	DWORD	wReserve1;		// Reserve2
} MSG_VIRTUAL;

typedef tagMSG_VIRTUAL* LPMSG_VIRTUAL; // I get error here

I get an error on the bottom line:
error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token

How can I solve this??

Thanks
 
Code:
typedef [B]struct[/B] tagMSG_VIRTUAL* LPMSG_VIRTUAL;

With the addition of 'struct' this now parses correctly.
 
thanks

thanks ian ray :) It now works,

If you have time, could you explain why it needed this???

If not, no worries,

:)
 
The keyword struct is needed in this case because there is no type named 'tagMSG_VIRTUAL'.

The declaration...
Code:
typedef struct tagMSG_VIRTUAL{
    ...
} MSG_VIRTUAL;

...defines two types:
Code:
struct tagMSG_VIRTUAL
MSG_VIRTUAL

Some compilers might have a quirk that allows 'tagMSG_VIRTUAL' to be recognized without the 'struct' keyword, but (as you have discovered) gcc does not accept it :D

FWIW (and YMMV) I like to avoid polluting the symbol table unnecessarily, so the original code would become:
Code:
typedef struct {
	DWORD	dwType;			// message type 
	WORD	wVersion;		// the version number for the message. Filled in by the derived(or real) message
	WORD	wReserve2;	
	DWORD	wReserve1;
} MSG_VIRTUAL;

typedef MSG_VIRTUAL* LPMSG_VIRTUAL;

Happy programming!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.