[libvirt] how to print size_t in LGPLv2+ program

Eric Blake eblake at redhat.com
Tue Aug 17 23:21:24 UTC 2010


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 at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100817/670406da/attachment-0001.sig>


More information about the libvir-list mailing list