C code you should never use in production
Publish date: 1 Oct 2012
Here’s a stupid little C trick which amuses me. Consider a C array:
To access element 3, you would use
This is just shorthand for a pointer dereference
This is just addition, which is associative, so it’s the exact equivalent of
which gives you
which is perfectly valid C.
To prove that, consider this simple program
After compilation
I would strongly caution against ever using this in production. Your colleagues will worry about you if they see it during a code review or when working on code you wrote. If you don’t think they would flag it, you should be worrying about them instead.