Thread: 32-bit unsigned inetegers.

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    11

    32-bit unsigned inetegers.

    I need to have a variable store the number: 4294967295.

    The line of code:
    Code:
    long int unsigned checksum = 4294967295;
    Generates the warning:
    [Warning] this decimal constant is unsigned only in ISO C90

    Which - in my infinite ignorance - leads me to believe I must find a different compiler. How can I solve this problem?
    Last edited by joecaveman; 02-23-2006 at 05:02 AM.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    you have the data type scrambled (when declaring long keyword int is optional and rarly used with long) There is no guarentee that long is 32 bits. could be 64 bits on a 64-bit computer.
    Code:
    unsigned long checksum = 42...
    Last edited by Ancient Dragon; 02-23-2006 at 05:50 AM.

  3. #3
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Use 4294967295u, with the u suffix to indicate unsignedness.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by Rashakil Fol
    Use 4294967295u, with the u suffix to indicate unsignedness.
    you don't really need that -- the compiler will figure it out from the integer's data type. But I suppose some compilers might complain if the 'u' is not present.

  5. #5
    Registered User OnionKnight's Avatar
    Join Date
    Jan 2005
    Posts
    555
    Also in cases like these it would be prettier and easier to understand if you used hex instead; 0xFFFFFFFF

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I like
    Code:
    (unsigned)-1
    or an equivalent.
    you have the data type scrambled (when declaring long keyword int is optional and rarly used with long)
    The order of keywords doesn't matter. const unsigned long int is exactly the same as unsigned long const int.
    There is no guarentee that long is 32 bits. could be 64 bits on a 64-bit computer.
    That's why you should use (unsigned)-1 or ULONG_MAX (in <limits.h>).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying 32 bits into 16 bit integer???
    By blackCat in forum C Programming
    Replies: 4
    Last Post: 02-17-2009, 10:00 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 07:35 AM
  5. can someone check this out and let me know ?
    By javaz in forum C Programming
    Replies: 5
    Last Post: 01-21-2002, 02:13 PM