[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to print size_t in LGPLv2+ program
From: |
Eric Blake |
Subject: |
Re: how to print size_t in LGPLv2+ program |
Date: |
Tue, 17 Aug 2010 17:21:24 -0600 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.7) Gecko/20100720 Fedora/3.1.1-1.fc13 Lightning/1.0b2pre Mnenhy/0.8.3 Thunderbird/3.1.1 |
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 address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
Message not available
Message not available
Re: how to print size_t in LGPLv2+ program, Paolo Bonzini, 2010/08/23