expected '=', ',', ';', 'asm' or '__attribute__' before '*' token

Discussion in 'iOS Programming' started by wanting2learn, Oct 23, 2010.

  1. wanting2learn macrumors newbie

    Joined:
    Aug 19, 2010
    #1
    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
     
  2. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
    Code:
    typedef [B]struct[/B] tagMSG_VIRTUAL* LPMSG_VIRTUAL;
    With the addition of 'struct' this now parses correctly.
     
  3. wanting2learn thread starter macrumors newbie

    Joined:
    Aug 19, 2010
    #3
    thanks

    thanks ian ray :) It now works,

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

    If not, no worries,

    :)
     
  4. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #4
    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!
     
  5. wanting2learn thread starter macrumors newbie

    Joined:
    Aug 19, 2010

Share This Page