Skip to content

Instantly share code, notes, and snippets.

@willglynn
Created October 5, 2012 18:50
Show Gist options
  • Save willglynn/3841654 to your computer and use it in GitHub Desktop.
Save willglynn/3841654 to your computer and use it in GitHub Desktop.
Negative array indices
#include <stdio.h>
int main() {
struct {
int scalar;
int array[5];
} some_struct;
some_struct.scalar = 5;
printf("%i\n", some_struct.array[-1]);
return 0;
}
@willglynn
Copy link
Author

clang compiles this -- at any optimization level -- to:

leaq    L_.str(%rip), %rdi
movl    $5, %esi
xorb    %al, %al
callq   _printf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment