3 ms·
$ cat sizeof.c #include <stdio.h> int main(int argc, char *argv[]) { printf("%zu\n", sizeof(int[argc - 2])); } $ make -B sizeof cc s
by sigjuice 7y ago
$ cat sizeof.c
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%zu\n", sizeof(int[argc - 2]));
}
$ make -B sizeof
cc sizeof.c -o sizeof
$ ./sizeof foo
0
$ ./sizeof
17179869180
- saagarjha 7y agoThis can yield surprising results even without undefined behavior. For example: https://godbolt.org/z/fwhLH4 https://godbolt.org/z/fwhLH4
- sigjuice 7y agoThis is what I see visit your link. I think this is easily explained. What might I be missing? ASM generation compiler returned: 0 Execution build compiler returned: 0 Program returned: 44 ./output.s PS: I did not examine the assembly code
- saagarjha 7y agoIt calls printf. Perhaps this is a better example: https://godbolt.org/z/fwhLH4 https://godbolt.org/z/fwhLH4. (I updated the link above, too.)