unsigned int and unsigned long int

This is a discussion on unsigned int and unsigned long int within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> int main (void) { printf("&#37;u\n",sizeof (long long int)); return 0; } Output of VS2008 Express: 8...

  1. #16
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Code:
    #include <stdio.h>
    int main (void)
    {
    	printf("&#37;u\n",sizeof (long long int));
    	return 0;
    }
    Output of VS2008 Express:
    8
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    I'm sure it wasn't like that before, if memory serves.
    I'm going to see do some research on the matter.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by Elysia View Post
    These types are defined or typedefed to the appropriate type
    C99 specifies that they are typedefs.
    Quote Originally Posted by Dave_Sinkula View Post
    Even the uintN_t are optional additions to C99.
    Clarification:
    3 These types are optional. However, if an implementation provides integer types with
    widths of 8, 16, 32, or 64 bits, no padding bits, and (for the signed types) that have a
    two’s complement representation, it shall define the corresponding typedef names.
    Last edited by robwhit; 03-05-2008 at 01:59 PM.

  4. #19
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    I tried to print out the size of the long int in my 64 bit machine and it generates 8 but in the 32 bit machine it is 4..

  5. #20
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by -EquinoX- View Post
    I tried to print out the size of the long int in my 64 bit machine and it generates 8 but in the 32 bit machine it is 4..
    Yes, that'll match what I said in the second post in this thread.

    --
    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.

  6. #21
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by -EquinoX- View Post
    I tried to print out the size of the long int in my 64 bit machine and it generates 8 but in the 32 bit machine it is 4..
    And? That's allowed. There is no reason that it should be the same. If you need to have an integer of a certain size, then you can't rely on the basic types of int and long, but you need to use the typedef's int_32t or whatever they're called. You'll get whatever size (short, int, long, etc.) that is a 32-bit integer.

  7. #22
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Standard C specifies
    * minimum value for an object of type long int LONG_MIN -2147483647

    * maximum value for an object of type long int LONG_MAX +2147483647

    * maximum value for an object of type unsigned long int ULONG_MAX 4294967295
    The rest is upto compiler to decide

    PS. compiler can decide to extend these regeons:
    The values given below shall be replaced by constant expressions suitable for use in #if preprocessing directives. Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.
    Last edited by vart; 03-05-2008 at 03:28 PM.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  8. #23
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    well I guess my problem here is this, on my 32 bit machine, I have:

    typedef int int_4
    typedef unsigned int_u4;
    typedef long long int int_8;

    and I have to find int_4, int_u4 int_8 in th3 64 bit machine.. however I tested that they are all the same, so I just assign the same value??

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    If they're the same, what's the problem?
    Just let the typedefs be, they're right after all.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #25
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    I mean I should have int_8 as 8, because I want it to be 8 byte in 64 bit machine

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    So it wasn't actually 8 bytes on the 32-bit machine???
    Long long int is 8 bytes. Both on 32 and 64.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #27
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by -EquinoX- View Post
    well I guess my problem here is this, on my 32 bit machine, I have:

    typedef int int_4
    typedef unsigned int_u4;
    typedef long long int int_8;

    and I have to find int_4, int_u4 int_8 in th3 64 bit machine.. however I tested that they are all the same, so I just assign the same value??
    What do you mean by "all the same"? You mean int and long long are the same size on your 64-bit machine? I suppose that's possible.

    Anyway, I don't think you've ever said what compiler you're using -- but if you poke around your header files, you may find a stdint.h header file which will have the typedefs you need in it. (IOW: you're not supposed to be defining these things yourself, you need to use the types the compiler knows about.) I would expect that you should have a line that defines a int32_t type, which is the four-byte integer you're panting for.

  13. #28
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    the thing is I want to have int_8 to be 8 on a 64 bit machine and int_8 to be 4 on a 32 bit machine.. the same thing as in int_u8

    I also want int_4 to be 4 in 32 bit machine but I want it to be int_4 to be 8 in a 64 bit machine..

    if you understand what I mean so I have to find the correct type that would let me do this:

    typedef ______ int_u4(that will generate sizeof 4 in 32 bit machine and 8 when in 64 bit machine)

  14. #29
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    This really defies the reason to use typedefs. You also give them a really misleading name. So why are you doing this again?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #30
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by -EquinoX- View Post
    the thing is I want to have int_8 to be 8 on a 64 bit machine and int_8 to be 4 on a 32 bit machine.. the same thing as in int_u8

    I also want int_4 to be 4 in 32 bit machine but I want it to be int_4 to be 8 in a 64 bit machine..

    if you understand what I mean so I have to find the correct type that would let me do this:

    typedef ______ int_u4(that will generate sizeof 4 in 32 bit machine and 8 when in 64 bit machine)
    I'm pretty sure that's the complete opposite of what you want, in that it makes no sense.

    Edit: The whole point of this typedef thing is that this way you know that your variables are the same size wherever you go. If that's not what you want, then we've wasted this whole thread.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 04:45 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Replies: 3
    Last Post: 05-13-2007, 09:55 AM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 09:54 PM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 12:58 PM

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