[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] how to print size_t in LGPLv2+ program

On 08/17/2010 04:33 PM, Bruno Haible wrote:
>> Which means you _can't_ use "%lu",(unsigned long)size_t_val.
> You _can_ use this. It will work as long as each of your program's data
> structures is less than 4 GB large. Remember that size_t values get
> larger than 4 GB only if you have a memory object (array) that is larger
> than 4 GB.

That's a safe assumption if you are talking about sizeof(object), as it
is unlikely that anyone is intentionally compiling .o files with objects
that are statically allocated to be that large.  But it is not a safe
assumption when using size_t as the argument to hold a user-specified
value matching the size of an dynamically allocated array, and goes
against the GCS mantra of no arbitrary limits (maybe the user really
does have a reason that they wanted a 4 gigabyte string loaded into
memory on a 64-bit machine).  In other words, I think your statement is
true only for a subset of the valid uses of printing a size_t value.

Eric Blake   eblake redhat com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]