stdint: no love for C++?

This is a discussion on stdint: no love for C++? within the C++ Programming forums, part of the General Programming Boards category; So stdint and exact-width types are part of the new C standard, but not C++. Fortunately, I can still #include ...

  1. #1
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591

    stdint: no love for C++?

    So stdint and exact-width types are part of the new C standard, but not C++. Fortunately, I can still #include <stdint.h> (although not portably); however what makes least sense is that, although the XintN_t types are made available, their counterpart max sizes, XINTN_MAX defines, are being held back by an "#if !defined ( __cplusplus) || defined (__STDC_LIMIT_MACROS)"

    Why is this? Why allow C++ to include the types, but not their max sizes? What would be the danger in removing the ifdef from the header? Or re-defining the macro in my own code?

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Because C++ has its own way of handling limits. Its nothing personal, just an attempt to maintain uniformity within C++. Not uniformity across the two languages.

  3. #3
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    I've heard that the next C++ standard aims to aspire to the very same... but in either case, how do I go about this:
    Code:
    uint64_t max_val = UINT64_MAX
    in C++?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Since you know by definition this had better be a 64-bit type, 0xffffffffffffffffull?

    Or (and also I didn't try this one either) maybe numeric_limits<unsigned long long>.max?
    Last edited by tabstop; 10-22-2008 at 04:25 PM.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    1) Boost contains <boost/cstdint.hpp>. It includes <stdint.h> where available, emulates it where the underlying types are available, and you're screwed elsewhere anyway.

    2) Use std::numeric_limits. <stdint.h> only contains typedefs for types that the compiler supports anyway, and thus there's a very good chance that numeric_limits is specialized for them. (By the way, max is a function. Thus, std::numeric_limits<uint64_t>::max(). Also, beware of the min() and max() macros in windows.h.)

    Why is this? Why allow C++ to include the types, but not their max sizes?
    Interesting question - but one better asked at the support forum of whatever compiler does this.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Thanks, I'm using "std::numeric_limits<uint64_t>::max()" now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unconditional Love
    By jrahhali in forum A Brief History of Cprogramming.com
    Replies: 87
    Last Post: 05-17-2005, 01:18 AM
  2. Love - learned or inherent?
    By axon in forum A Brief History of Cprogramming.com
    Replies: 42
    Last Post: 01-24-2005, 11:09 AM
  3. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM
  4. "if you love someone" :D
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-02-2003, 01:10 AM
  5. What signs are there of that a girl is in love with you?
    By A_guy in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 05-21-2003, 07:48 AM

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