Code::Blocks doesn't like my enums and typedefs

This is a discussion on Code::Blocks doesn't like my enums and typedefs within the C++ Programming forums, part of the General Programming Boards category; I am now using Code::Blocks as my C++ IDE. I coded my source in Microsoft C++ Express previously and it ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    14

    Question Code::Blocks doesn't like my enums and typedefs

    I am now using Code::Blocks as my C++ IDE. I coded my source in Microsoft C++ Express previously and it compiled fine. When compiling the same code in Code::Blocks (using the GCC compiler) I receive this syntax error after every line a typedef or enum type is used:
    Code:
    error: expected primary-expression before ‘;’ token
    I am using Linux instead of Windows but I believe this is irrelevant.
    Here is some source code:

    declarations.h
    Code:
    #ifndef _DECLARATIONS
    #define _DECLARATIONS
    
    typedef unsigned char  byte;
    typedef unsigned short uint16;
    typedef unsigned long  uint32;
    typedef unsigned long long uint64;
    
    #define READ_UINT16(x) (*(uint16*)(x))
    #define READ_UINT32(x) (*(uint32*)(x))
    #define READ_UINT64(x) (*(uint64*)(x))
    #define READ_FLOAT(x) (*(float*)(x))
    
    #endif
    convert_mesh.h
    Code:
    #include <string>
    #include <iostream>
    #include <fstream>
    #include "declarations.h"
    using namespace::std;
    
    class convert_mesh
    {
    public:
        enum mesh_t { UNIT, BACKGROUND, PLAYER };
        enum material_detail_t { SIMPLE, COMPLEX };
    
        struct declaration_t {
            uint32 type;
            uint32 offset;
            uint32 size;
        };
    
        struct index_t {
            size_t	index_s;
            uint16	*index;
    
            material_detail_t	detail;
    
            size_t	tga_diffuse_s,
                    tga_normal_s,
                    tga_bloom_s,
                    tga_specular_s,
                    tga_lighting_s,
                    tga_texture_s;
    
            string	tga_diffuse,
                    tga_normal,
                    tga_bloom,
                    tga_specular,
                    tga_lighting,
                    tga_texture;
    
            float 	dimension[9];
        };
    
        struct geometry_t {
            byte	no_vertices;
    
            size_t	positions_s,
                    uv_s,
                    normals_s;
            float	*positions,
                    *uv,
                    *normals;
        };
    
    	void readMeshHeader	(size_t&, byte[]);
    	void readMeshData	(size_t&, byte[]);
    
    	void readIndexHead	(size_t&, byte[], size_t);
    	void readIndex		(size_t&, byte[], size_t);
    	void readMaterials	(size_t&, byte[], size_t);
    
    	void readGeometryHead (size_t&, byte[], size_t);
    	void readPositions	(size_t&, byte[], size_t);
    	void readUV			(size_t&, byte[], size_t);
    	void readNormals	(size_t&, byte[], size_t);
    	void readReference	(size_t&, byte[], size_t);
    	void readIndexMap	(size_t&, byte[], size_t);
    	void unknownStruct	(size_t&, byte[]);
    
    	void writeColladaDAE();
    
    private:
    	mesh_t			mesh;			// Indicates what type of mesh.
    
    	size_t			declaration_s,
    					index_s,
    					geometry_s,
    					index_map_s;
    	declaration_t	*declaration;	// Read at the Head of the file.
    	index_t			*index;			// 16bit Index Buffer/Triangles.
    	geometry_t		*geometry;		// Positions, UV and Normals.
    	declaration_t	*index_map;		// This is for player models only.
    };
    
    #endif
    convert_mesh.cpp
    Code:
    #include "convert_mesh.h"
    
    void convert_mesh::readMeshHeader(size_t &cursor, byte fBuffer[])
    {
    	uint64 signature = READ_UINT64(&fBuffer[0]);
    
    	switch (signature)
    	{
    	// A 'unit' mesh with the extension .am
    	case 0xA31B0061E1:
    		mesh = UNIT;
    		cursor += sizeof uint64;
    		break;
    	// A 'background' mesh with the extension .m
    	case 0x9BCAFE1515:
    		mesh = BACKGROUND;
    		cursor += sizeof uint64;
    		break;
    	// A 'player' mesh with the extension .wm
    	case 0xAF43342ABF:
    		mesh = PLAYER;
    		cursor += sizeof uint64;
    		break;
    	default:
    		cout << "Incorrect file type or unhandled formated." << endl;
    		exit(2);
    		break;
    	}
    }
    The lines that cause this error are the
    Code:
    cursor += sizeof uint64;.
    It also gives the same error when using my typedefs that can be seen in declarations.h.

    Thanks in advance! This one really has me stumped and I can't continue with my project
    Last edited by muehl; 02-12-2009 at 08:51 AM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And what error are you seeing? That would help a fair bit.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    14
    It's right at the top. I'll post it again here:
    Code:
    error: expected primary-expression before ‘;’ token

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Hmm, perhaps you should append LL to your 64-bit constants in your case-labels - I suspect if you move the mesh = ... to below the line after, the error will still be on the first line after case ...:

    That is an educated guess, I haven't tried to reproduce the problem on my machine.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    14
    Thanks for the fast reply. I have realized I have inaccurately described the problem. The issue is actually with the lines:
    Code:
    cursor += sizeof uint64;
    Code:
    error: expected primary-expression before ; token|
    The GCC compiler expects the sizeof syntax to be different?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    Where have you declared UNIT, BACKGROUND, PLAYER, etc?

    By the way, do not place a using directive at file scope in a header file. Also, note that names that begin with an underscore followed by an uppercase letter are reserved to the implementation for any use, so you should rename your header inclusion guard macro name.

    Quote Originally Posted by muehl
    The GCC compiler expects the sizeof syntax to be different?
    It should be:
    Code:
    cursor += sizeof(uint64);
    The parentheses are required when sizeof is used on a type name.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Oct 2005
    Posts
    14
    Thanks heaps for the help guys. I was missing the parentheses, easy mistake when i've been using VC++ for years, right, right? XD

    Also thanks for the header implementation tips. I think its time to do some revision.

    Thanks again!

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by muehl View Post
    Thanks heaps for the help guys. I was missing the parentheses, easy mistake when i've been using VC++ for years, right, right? XD

    Also thanks for the header implementation tips. I think its time to do some revision.

    Thanks again!
    No, it's nothing to do with VC++ - it is about the fact that sizeof(type) and sizeof variable are different syntax - don't ask me why they did it that way. sizeof(variable) is also allowed, so for the sake of a set of parenthesis vs. consistency, I tend to use sizeof(x) where x can be anything.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    2,456
    VC++ supports it with no parentheses? that's non-standard and should be avoided. it definitely supports it WITH the parentheses, so I'd suggest always using them.

  10. #10
    Registered User
    Join Date
    Oct 2005
    Posts
    14
    I've been compiling it like that in VC++ fine for months, GCC gives the syntax error. I will be using parenthesis from now on whichever compiler I use.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elkvis View Post
    VC++ supports it with no parentheses? that's non-standard and should be avoided. it definitely supports it WITH the parentheses, so I'd suggest always using them.
    As I said, it's not about the VC++, but about the origin of the item you take size of. If it is a variable, it's happy with no parenthesis. If it is a type, you have to have parenthesis - both in standard C and in Visual Studio.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User
    Join Date
    Oct 2005
    Posts
    14
    But the examples I used above were types, not variables.

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    Quote Originally Posted by Elkvis
    VC++ supports it with no parentheses?
    No, there does not appear to be such a compiler extension, at least not with MSVC8 (Visual Studio 2005). I think matsp is right: muehl just never had occasion to use sizeof on a type name when using MSVC.

    EDIT:
    Quote Originally Posted by muehl
    But the examples I used above were types, not variables.
    Which version of MSVC did you use? I suggest testing with this:
    Code:
    #include <iostream>
    
    int main()
    {
        std::cout << sizeof int << std::endl;
    }
    MSVC8 correctly gave me the compile error: ".\main.cpp(5) : error C2062: type 'int' unexpected"
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  14. #14
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by muehl View Post
    But the examples I used above were types, not variables.
    Well, I just tried this:
    Code:
      int i;
      cout << sizeof i;
      cout << sizeof int;
    with both Visual Studio C++ 6.0 and gcc, and both complain about the sizeof int, but not about sizeof i; - it may be that newer versions of Visual C++ are different - I'm not going to install a newer compiler only to (dis)prove your point.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #15
    Registered User
    Join Date
    Oct 2005
    Posts
    14
    hey i'm not arguing just stating the way it is. Thanks for the help.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21