lua-users home
lua-l archive

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


On Fri, Dec 6, 2013 at 9:41 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> > (For instance, in my Linux, printf has a modifier for long long
>> > [ll], but there is no modifier for int64_t.)
>>
>> Are you sure that you don't have PRI{d,i,o,u,x,X}64 on your system?
>
> No, I am not.  I did not say that there is no trick (using an extra
> non-C89 header file and a convoluted syntax) to print an int64_t.  I
> said that printf has no modifier for int64_t, while it has one for long
> long. That is what I mean by "better support" for long long.

I got your point. Though I think "%ll*" are also non-C89.

> See next example:
>
> void foo (void) {
>   printf("%" PRId32  " %lld", (int64_t)9, (long int)10);
> }
>
> temp.c:7: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long long int’
> temp.c:7: warning: format ‘%lld’ expects type ‘long long int’, but argument 3 has type ‘long int’
>
> Why the message is not "format ‘%PRId32’ expects type ‘int32_t’,
> but argument 2 has type ‘int64_t’ ?

I think that is because the PRI macros should expand to a character
string literal containing a length modifier and the length modifiers
are only specified for standard types (that is, non-extended types);
as follows:

"7.8.1 Macros for format specifiers

Each of the following object-like macros expands to a character string literal
containing a conversion specifier, possibly modified by a length
modifier, suitable for use within the format argument of a formatted
input/output function when converting the corresponding integer type*.
These macro names have the general form of PRI (character string
literals for the fprintf and fwprintf family) or SCN (character string
literals for the fscanf and fwscanf family), followed by the
conversion specifier, followed by a name corresponding to a similar
type name in 7.18.1. (...) [1]"

[1] ISO/IEC 9899:1999

Regards,
-- 
Lourival Vieira Neto