简体   繁体   中英

Why I don't get segmentation fault when using argc and argv?

I have an OpenGL program with my main with 2 parameters I am compiling with xCode on macOS

int main (int argc, char **argv)
{
...
glutInit(&argc, argv);

I studied that if i don't compile with a.out and 2 values after I should get segmentation fault but I'm not getting it compiling without those values.

The segmentation fault to which you are alluding is a particular manifestation of program undefined behaviour .

But undefined behaviour is exactly that: you don't know what's going to happen.

Which is why you need to check the value of argc before reading any of argv .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM