On Fri, Mar 06, 2020 at 04:36:40PM -0600, Eric Blake wrote:
On 3/4/20 9:17 AM, Richard W.M. Jones wrote:
>+ return INT64_C (1024*1024);
This looks fishy. POSIX says that:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/stdint.h.html#t...
"The argument in any instance of these macros shall be an unsuffixed
integer constant with a value that does not exceed the limits for
the corresponding type.
...For example, if uint_least64_t is a name for the type unsigned
long long, then UINT64_C(0x123) might expand to the integer constant
0x123ULL."
In fact, in glibc's /usr/include/stdint.h, we have:
# if __WORDSIZE == 64
# define INT64_C(c) c ## L
# else
# define INT64_C(c) c ## LL
# endif
Your code works by sheer luck (expanding to the three tokens '1024',
'*', '1024L'), which in turn results in an expression with 64-bit
type, but in general, INT64_C should ONLY be used on a single
literal value, not an arbitrary expression.
But you really don't need to use INT64_C; we can just rely on C's
automatic type promotion to turn our 'int' expression 1024*1024 into
the proper int64_t return value.
Yeah I don't know what I was thinking here. Obviously bogus :-/
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages.
http://libguestfs.org