type of sizeof

Discussion in 'C++' started by Tommi =?UTF-8?B?TcOka2l0YWxv?=, May 26, 2004.

  1. Hi,

    what is the type of sizeof?

    Here is some lines of code from a programm, which I'm porting to x86-64:

    char buffer[512];
    unsigned size = content_size;
    while (size > 0
    && (in.read(buffer, std::min(sizeof(buffer), size)), in.gcount() > 0))
    ...

    This does not work, because sizeof(buffer) is not of type unsigned. My
    complier (g++-3.3 on linux) tells me:
    error: no matching function for call to `min(long unsigned int,
    unsigned int&)'

    So what is the right (and portable) type to use here?


    Tommi
    Tommi =?UTF-8?B?TcOka2l0YWxv?=, May 26, 2004
    #1
    1. Advertising

  2. "Tommi Mäkitalo" <> wrote in message
    news:c92s1p$nth$...
    > Hi,
    >
    > what is the type of sizeof?


    size_t (or std::size_t if you prefer)

    >
    > Here is some lines of code from a programm, which I'm porting to x86-64:
    >
    > char buffer[512];
    > unsigned size = content_size;
    > while (size > 0
    > && (in.read(buffer, std::min(sizeof(buffer), size)), in.gcount() >

    0))
    > ...
    >
    > This does not work, because sizeof(buffer) is not of type unsigned. My
    > complier (g++-3.3 on linux) tells me:
    > error: no matching function for call to `min(long unsigned int,
    > unsigned int&)'
    >
    > So what is the right (and portable) type to use here?
    >


    size_t.

    john

    > Tommi
    John Harrison, May 26, 2004
    #2
    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. Derek
    Replies:
    7
    Views:
    24,325
    Ron Natalie
    Oct 14, 2004
  2. Trevor

    sizeof(str) or sizeof(str) - 1 ?

    Trevor, Apr 3, 2004, in forum: C Programming
    Replies:
    9
    Views:
    626
    CBFalconer
    Apr 10, 2004
  3. Vinu
    Replies:
    13
    Views:
    1,414
    Lawrence Kirby
    May 12, 2005
  4. Yevgen Muntyan

    #define ALLOCIT(Type) ((Type*) malloc (sizeof (Type)))

    Yevgen Muntyan, Feb 9, 2007, in forum: C Programming
    Replies:
    10
    Views:
    897
    Yevgen Muntyan
    Feb 13, 2007
  5. Alex Vinokur
    Replies:
    15
    Views:
    704
    Default User
    Jun 12, 2006
Loading...

Share This Page