Re: size_t ... standards

Discussion in 'C++' started by Howard Hinnant, Jun 29, 2003.

  1. In article <hfELa.34882$>, MiniDisc_2k2
    <> wrote:

    | Of course,
    | I wouldn't worry about including the right header because they all define
    | size_t as a typedef to unsigned int.

    That's not a very good assumption for portability. size_t must be a
    typedef to the same type that a sizeof() expression results in. That
    type must be able to represent the largest array types the platform is
    capable of supporting, and must also be unsigned.

    Here is a way to investigate the matter on your platform:

    #include <iostream>
    #include <typeinfo>
    #include <stddef.h>

    int main()
    {
    std::cout << "typeof(sizeof) = " << typeid(sizeof(0)).name() << '\n';
    std::cout << "typeof(size_t) = " << typeid(size_t).name() << '\n';
    }

    On the platform on which I tested this code it resulted in:

    typeof(sizeof) = unsigned long
    typeof(size_t) = unsigned long

    If it doesn't print out the same type in both statements, then your C++
    compiler (or library) has a bug.

    --
    Howard Hinnant
    Metrowerks
     
    Howard Hinnant, Jun 29, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Howard Hinnant

    Re: size_t ... standards

    Howard Hinnant, Jun 29, 2003, in forum: C++
    Replies:
    5
    Views:
    3,585
    Jim Fischer
    Jun 30, 2003
  2. Chris \( Val \)

    Re: for(size_t a=begin();a!=end();++a){}

    Chris \( Val \), Jul 13, 2003, in forum: C++
    Replies:
    2
    Views:
    365
    John Harrison
    Jul 14, 2003
  3. Marc Schellens

    auto_ptr to char[ size_t]?

    Marc Schellens, Jul 16, 2003, in forum: C++
    Replies:
    8
    Views:
    3,335
    Karl Heinz Buchegger
    Jul 17, 2003
  4. Alex Vinokur
    Replies:
    9
    Views:
    831
    James Kanze
    Oct 13, 2008
  5. Alex Vinokur
    Replies:
    1
    Views:
    609
Loading...

Share This Page