Thread: Copying constant amount of data

  1. #16
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You know, that's what std::size_t and std::ptrdiff_t are for. They're in <cstddef>.

    On some systems, you can also find intptr_t and uintptr_t. They'd be in the C99 header <stdint.h>. Boost also provides them, I think, as boost::intptr_t and boost::uintptr_t in <boost/stdint.hpp>.
    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

  2. #17
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    And, you can't get typedefs that depend on architecture with the preprocessor. Instead use this;
    Code:
    template<int bit_size> struct Helper
    {
    };
    
    template<> struct Helper<16>
    {
        typedef   int16_t   intw;
        typedef  uint16_t  uintw;
    };
    
    template<> struct Helper<32>
    {
        typedef   int32_t   intw;
        typedef  uint32_t  uintw;
    };
    
    template<> struct Helper<64>
    {
        typedef   int64_t   intw;
        typedef  uint64_t  uintw;
    };
    
    typedef Helper<sizeof(void *)*CHAR_BIT>::intw intw;
    typedef Helper<sizeof(void *)*CHAR_BIT>::uintw uintw;
    This, of course, relies on the types intXX_t and uintXX_t types being declared on your target system - which is not guaranteed either, IIRC.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. question about a working linked list
    By cold_dog in forum C++ Programming
    Replies: 23
    Last Post: 09-13-2006, 01:00 AM
  3. Reading a file with Courier New characters
    By Noam in forum C Programming
    Replies: 3
    Last Post: 07-07-2006, 09:29 AM
  4. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  5. All u wanted to know about data types&more
    By SAMSAM in forum Windows Programming
    Replies: 6
    Last Post: 03-11-2003, 03:22 PM