gcc optimising away compound statement
问题 I am having an issue with implementing a push_back operator for a generic resizable vector in c. For genericity I need to use a void pointer as an argument, but in practice I want to give it values directly. When I compile the below code with gcc -o t test.c -std=c99 , it prints 10 as I expect. When I add -O1 (or higher) to the compile options, the program prints 0 . I think the problem is in the smemcpy code, as when I replace it with memcpy I no longer have this problem. Simplified code: