Platform independent size_t Format specifiers in c? -


I want to print a type of type size_t in C but it seems that Size_t is the nickname for different variable types on different architectures. For example, the following code on a machine (64-bit) does not throw any warning:

  Size_t size = 1; Printf ("size is% ld", size);  

But the above code on my other machine (32-bit) generates the following warning message:

WARNING: Expecting format '% ld' Long intestine ', but type' size_t * 'in logic 3

I suspect that this indicator is due to the difference in size, so that my 64-bit machine size_t is placed in long intervals ( "% ld" ), while my 32-bit machine is aliased for the second type on size_t is .

P> Yes: Use the z length modifier:

  size_t size = (four) of size; Printf ("size is% zd \ n", size is); // decimal size_tprintf ("size is% zx \ n", size is); // hex size_t  

The other length modifiers available are hh (for char ), h < For Code> Short , L (for long ), ll ( for long time ), j (for intmax_t ), t (for ptrdiff_t ), and L See <§7.19.6.1 (7) of the C99 standard for ( for a long time )


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -