What does the C standard say about...

This is a discussion on What does the C standard say about... within the C Programming forums, part of the General Programming Boards category; int? Is it signed or unsigned or is it implementation defined like char?...

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    5

    What does the C standard say about...

    int? Is it signed or unsigned or is it implementation defined like char?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    int is signed unless declared as unsigned.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    5

    thanks

    Thanks for the clarification. You wouldn't mind telling which section of the C Standard Reference Manual says this, would you?

  4. #4
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    Code:
    6.2.5 Types
    
    4. There are five standard signed integer types, designated as signed char, short
    int, int, long int, and long long int.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    5

    Thanks again

    Thank you, cwr.

    I have one more question: a hexedecimal value (0x0f) is int, too, according to the standard - correct?

    If that's the case. If I did this: 0x0f. That looks like I'm declaring a 1 byte (e.g char) value to work with, but, since hex's are int. it's actually taken (by the compiler/C) as 0x0000000f - an int.

    Am I wrong or right?

  6. #6
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    If you have a copy of the standard, see 6.4.4.1 (ISO).

    In the case of 0x0f, it will be treated as an int, because it's the first type it will fit (char is not counted). If the constant is too big to fit in int, it will try unsigned int, long int, unsigned long int, long long int (C99), unsigned long long int (C99).

    Were it decimal, it would first try int, then long int, then long long int (C99).

    In other words, on a int is 32 bits, long long is 64 bits system, the constant 4000000000 would be of type long long int, but the same value expressed in hex (0xee6b2800) will have type unsigned int.

    An integer constant will never have type char. Even if you expressed it as '\x0f' (a character constant), it is still of type int.

    Disclaimer: This is not something I generally pay too much attention to, and I'm summarising from a brief look at the standard. I may have interpreted it incorrectly, but I'm sure I will be corrected if so.
    Last edited by cwr; 12-06-2005 at 07:47 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bug in iterator comparison in C++ standard?
    By steev in forum C++ Programming
    Replies: 14
    Last Post: 07-12-2008, 12:02 AM
  2. Abstract Base Class and References
    By Thantos in forum C++ Programming
    Replies: 9
    Last Post: 10-13-2004, 01:35 PM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM
  5. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM

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