This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch to add snprintf/vsnprintf to libiberty


Kaveh R. Ghazi wrote:

B.  What do we return when n < real length?  n? real_length?
(`real_length' is the length the output would have been had we given a
large enough 'n'.)
The standard above says the number of characters transmitted ('n'),
but I *think* c99 says the number that *would* have been transmitted,
i.e. real_length.  Irix6.5 returns n while solaris2.8 returns
real_length.
I chose the real_length.

Definitely, this behavior - i.e., that conforming to the C99 standard - is the one which would be most useful for libstdc++-v3. For instance, consider this example from num_put::_M_convert_int (__convert_from_v calls snprintf and little more, not relevant for the present discussion):

...

#ifdef _GLIBCPP_USE_C99
// First try a buffer perhaps big enough.
int __cs_size = 64;
char* __cs = static_cast<char*>(__builtin_alloca(__cs_size));
int __len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
_S_c_locale);
// If the buffer was not large enough, try again with the correct size.
if (__len >= __cs_size)
{
__cs_size = __len + 1;
__cs = static_cast<char*>(__builtin_alloca(__cs_size));
__len = __convert_from_v(__cs, __cs_size, __fbuf, __v,
_S_c_locale);
}

...

Paolo.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]