_ptr and _srcptr types
Vincent Lefevre
vincent at vinc17.net
Tue May 22 06:32:09 UTC 2018
On 2018-05-22 08:18:18 +0200, Vincent Lefevre wrote:
> No, with variadic functions, a null pointer of some type is provided
> as an argument, and then the value is re-read as another pointer type
> (this is actually a simplification, because depending on the calling
> conventions, using incompatible types can just be meaningless). You
> do not have a conversion.
>
> For instance, something similar can be said between the 0 of type
> int and the 0 of type long: in a type conversion, the value does
> not change, and (int) 0 and (long) 0 compare equal. But if int is
> on 4 bytes and long is on 8 bytes, they are not interchangeable in
> a variadic function. Note that for pointers, this is even worse,
> since even in the case the size and alignment requirements are the
> same, the representation of the null pointer may still depend on
> the type.
With variadic functions, the constraints are even stronger than one
can deduce from representation. The standard says:
7.16.1.1 The va_arg macro
[...] If there is no actual next argument, or if type is not
compatible with the type of the actual next argument (as promoted
according to the default argument promotions), the behavior is
undefined, except for the following cases:
- one type is a signed integer type, the other type is the
corresponding unsigned integer type, and the value is
representable in both types;
- one type is pointer to void and the other is a pointer to a
character type.
So, for instance, (void*)0 and (char*)0 are interchangeable, but
not the other kinds of pointers (when the pointer types are not
compatible). And for integers, even if int and long have the same
size, same representation and same alignment requirements, (int)0
and (long)0 are not interchangeable.
--
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
More information about the gmp-devel
mailing list