type of sizeof

  • Thread starter Tommi =?UTF-8?B?TcOka2l0YWxv?=
  • Start date
T

Tommi =?UTF-8?B?TcOka2l0YWxv?=

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
 
J

John Harrison

Tommi Mäkitalo said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top