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

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

 



Philipp Marek <philipp@xxxxxxxxxxxxx> 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, schwab@xxxxxxx
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."


_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf


[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux