Define Uint8

This is a discussion on Define Uint8 within the C++ Programming forums, part of the General Programming Boards category; I'm trying to define a storage type Uint8. Heres my definition: #define Uint8 unsigned char But I get this error ...

  1. #1
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218

    Define Uint8

    I'm trying to define a storage type Uint8. Heres my definition:

    #define Uint8 unsigned char

    But I get this error when I try and use it:

    error C2061: syntax error : identifier 'Uint8'

    Could someone tell me what I'm doing wrong here? Thanks.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    Quote Originally Posted by mike_g View Post
    I'm trying to define a storage type Uint8. Heres my definition:

    #define Uint8 unsigned char

    But I get this error when I try and use it:

    error C2061: syntax error : identifier 'Uint8'

    Could someone tell me what I'm doing wrong here? Thanks.
    Seems like your #define is not making its way into the file it's supposed to. Does the following work?

    Code:
    #define Uint8 unsigned char
    int main()
    {
        Uint8 x;
        return 0;
    }
    If it were me I'd use a typedef, not a #define.

  3. #3
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Yeah I think you are right there. It works in main. I was trying to use it in a header file, but it wont work. I have it defined before my header include, so I don't know what would be causing this. I'm using VC++ atm if that makes any difference.

  4. #4
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Ok I worked it out now. It was all to do with the sequence of includes and definitions. I need to have my 'typedef's after using 'name space' and before my own includes, but 'name space' needs to come after the iostream include.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    You should put the typedef in the header, or in another header #include'd by the header that needs it.

    Forcing a certain order of includes is a bad idea.

  6. #6
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Oh yeah, that sounds like a good idea. Tbh my prog is pretty simple at the moment, but I'll get into the habit of doing that.

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    Quote Originally Posted by mike_g View Post
    Ok I worked it out now. It was all to do with the sequence of includes and definitions. I need to have my 'typedef's after using 'name space' and before my own includes, but 'name space' needs to come after the iostream include.
    Yeah. Definitely don't include a header into a namespace -- it completely breaks everything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer within a Struct
    By Bladactania in forum C Programming
    Replies: 11
    Last Post: 04-03-2009, 11:20 PM
  2. Why?!?
    By p3rry in forum C Programming
    Replies: 3
    Last Post: 01-08-2009, 12:52 PM
  3. size of an integer pointer
    By onebrother in forum C Programming
    Replies: 5
    Last Post: 07-09-2008, 12:49 PM
  4. edit controls in dialogs
    By Homunculus in forum Windows Programming
    Replies: 10
    Last Post: 02-23-2006, 03:38 PM
  5. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 09:22 AM

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