Reputation: 489
Is there any documentation specifying the meaning of a pointer cast applied to a literal in C?
For example:
int *my_pointer = (int *) 9
Is this compiler-dependent or part of the standard?
Edit: deleted misleading note based on comment below, thanks.
Upvotes: 0
Views: 125
Reputation: 62086
Pointer to integer and integer to pointer conversions are implementation-defined (see Annex J of the C standard).
Upvotes: 3
Reputation: 145899
int *my_pointer = (int *) 9
This does not point to the literal 9
. It converts the literal 9
to a pointer to int
. C says the conversion from an integer to a pointer type is implementation-defined.
int *my_pointer = &(int) {9};
This does. It makes my_pointer
points to an int
object of value 9
.
Upvotes: 5