gcc confused about what's an lvalue?
gcc is giving me invalid lvalue in assignment errors for:
-2[(size_t *)new] = 0;
Changing the code to the following makes it开发者_如何学编程 go away:
((size_t *)new)[-2] = 0;
but as far as I can tell, both are 100% equivalent in C. gcc has no problem using the former in non-lvalue expressions. Is this just a bug in gcc? I've tested it with several versions and got the same results.
I'm stupid. []
binds more tightly than -
, so this expression is actually reading index 2 and negating it.
精彩评论