_ptr and _srcptr types
gmpdevel at formauri.es
Tue May 22 02:46:50 UTC 2018
Vincent Lefevre wrote, On 2018-05-22 03:13:
> On 2018-05-20 22:07:36 +0200, Niels Möller wrote:
>> If that really is the case, most occurences of NULL or (void*)0 in
>> the argument list in the call of a varargs function would be
>> undefined behavior, right?
> Using NULL is never guaranteed to work as it can be defined as the
> integer 0. If (void*)0 is used in place of (char*)0, I assume that
> this is OK sue to the same representation and alignment requirements
> (note 48 mentions that the goal is interchangeability, and as
> I understand it, this necessary condition is also a sufficient
> condition). But if same representation and alignment requirements
> are not satisfied, I assume that this is undefined behavior.
The C11 standard also says:
1. A pointer to void may be converted to or from a pointer to any incomplete or object type. A pointer to any incomplete or object type may be converted to a pointer to void and back again; the result shall compare equal to the original pointer.
(Definition of object, p.5 §3.14: "region of data storage in the execution environment, the contents of which can represent values")
3. An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.55) If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.
4. Conversion of a null pointer to another pointer type yields a null pointer of that type. Any two null pointers shall compare equal.
Doesn't that allow using (void *)0 for the suggested purpose?
More information about the gmp-devel