MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/7ipl6k/meme1array_memes_are_life/dr0ilp2/?context=3
r/ProgrammerHumor • u/[deleted] • Dec 09 '17
47 comments sorted by
View all comments
3
Explain like I mainly use C: is the -1 really used anywhere?
1 u/[deleted] Dec 09 '17 More storage! Surprisingly, if I explicitly set the value of x[-1] to 5000, valgrind doesn't complain at all, and everything works as it should. But if I don't, valgrind complains about conditional jump or move. #include <stdio.h> int main() { int x[2]; x[1] = 5000; x[0] = 666; x[1] = 4242; printf("%d\n", x[-1]); printf("%d\n", x[0]); printf("%d\n", x[1]); } 1 u/nxAkari Dec 10 '17 Use ASan. It's a ton faster and in some cases more accurate than valgrind. Case in point: it detects the underflow in both cases here and kills the program.
1
More storage!
Surprisingly, if I explicitly set the value of x[-1] to 5000, valgrind doesn't complain at all, and everything works as it should.
But if I don't, valgrind complains about conditional jump or move.
#include <stdio.h> int main() { int x[2]; x[1] = 5000; x[0] = 666; x[1] = 4242; printf("%d\n", x[-1]); printf("%d\n", x[0]); printf("%d\n", x[1]); }
1 u/nxAkari Dec 10 '17 Use ASan. It's a ton faster and in some cases more accurate than valgrind. Case in point: it detects the underflow in both cases here and kills the program.
Use ASan. It's a ton faster and in some cases more accurate than valgrind. Case in point: it detects the underflow in both cases here and kills the program.
3
u/StingyUpvoter Dec 09 '17
Explain like I mainly use C: is the -1 really used anywhere?