Connecting Tech Pros Worldwide Forums | Help | Site Map

type of sizeof

Tommi Mäkitalo
Guest
 
Posts: n/a
#1: Jul 22 '05
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

John Harrison
Guest
 
Posts: n/a
#2: Jul 22 '05

re: type of sizeof



"Tommi Mäkitalo" <tommi@maekitalo.de> wrote in message
news:c92s1p$nth$1@online.de...[color=blue]
> Hi,
>
> what is the type of sizeof?[/color]

size_t (or std::size_t if you prefer)
[color=blue]
>
> 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() >[/color]
0))[color=blue]
> ...
>
> 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?
>[/color]

size_t.

john
[color=blue]
> Tommi[/color]


Closed Thread