autoconf
[Top][All Lists]
Advanced

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

Re: Question regarding sscanf() vs. off_t and similar


From: Andreas Schwab
Subject: Re: Question regarding sscanf() vs. off_t and similar
Date: Thu, 14 Sep 2006 15:01:47 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux)

Philipp Marek <address@hidden> writes:

> If I'm doing 
>       ino_t ino;
>       char *name;
>       sprintf("%Lu %s", ino, name);

Note that "L" is not a valid length modifier for integer formats.

> that works fine for 64bit systems, but writes trash for sizeof(ino_t) == 4.
>
> Is there an easy way to find the format strings (sprintf, printf, sscanf) for 
> various system types, or something like that?

Assuming you meant %llu instead of %Lu you can always add a cast to
unsigned long long to match the format.

> Or has somebody some already defined preprocessor magic to get this for some 
> variable?
> I'm thinking of something along the lines
>       #define FORMAT(x)
>         #if sizeof(x) == 4
>           "%l"
>         #else
>           #if sizeof(x) == 8
>             "%L"
>           #else
>             #error "Don't know size"
>           #endif
>         #endif

You can't use sizeof in preprocessor directives.  Besides that, the size
of an integer says nothing about its type.  For example, a 4 byte integer
can be either int or long on an ILP32 system, and an 8 byte integer can be
long or long long on an LP64 system.

Andreas.

-- 
Andreas Schwab, SuSE Labs, address@hidden
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




reply via email to

[Prev in Thread] Current Thread [Next in Thread]