Did you read it? Linus explains it pretty well.
It depends on highly obscure behavior. If one of the pointer operators of the tertiary operator evaluates to integer constant NULL (0), then the return value of the tertiary operator is coerced to have the type of the non-null operator (which is int *). And of course sizeof(*(int *)1) == sizeof(int). It relies on the fact that if it isn't an ICE, x * 0 will not be evaluated as null (remember sizeof cannot execute code) and the tertiary operator return will fall back to being of type void *. And sizeof(*(void *)x) != sizeof(int)
Like Linus points out, this is bad bad. There is no standardization for the sizeof(*(void*)) and it may very well equal sizeof(int) in a different compiler or even a future version of GCC
0
30 Mar 2018 07:53
u/obsessedcrf
in v/programming
Did you read it? Linus explains it pretty well.
It depends on highly obscure behavior. If one of the pointer operators of the tertiary operator evaluates to integer constant NULL (0), then the return value of the tertiary operator is coerced to have the type of the non-null operator (which is int *). And of course sizeof(*(int *)1) == sizeof(int). It relies on the fact that if it isn't an ICE, x * 0 will not be evaluated as null (remember sizeof cannot execute code) and the tertiary operator return will fall back to being of type void *. And sizeof(*(void *)x) != sizeof(int)
Like Linus points out, this is bad bad. There is no standardization for the sizeof(*(void*)) and it may very well equal sizeof(int) in a different compiler or even a future version of GCC