I have an application that uses the mmap system call, I was having an issue getting it to compile for hours looking as to why I was getting MAP_ANON and MAP_ANONYMOUS were undeclared, I had a smaller section of code that I used and I saw I could compile it just fine so I tried just a basic compile and that worked, I saw that it fails when you add -std=c99. Is there a specific reason that MAP_ANON and MAP_ANONYMOUS are not valid in the C99 standard? I know that they aren't defined by POSIX but are defined by BSD SOURCE so I just want to know why that is.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You probably want -std=gnu99
instead of -std=c99
. C99 mode explicitly disables (most) GNU extensions.
I wrote a simple test:
#include <sys/mman.h>
int a = MAP_ANONYMOUS;
In C99 mode, it doesn't find the value:
$ gcc -std=c99 -c d.c
d.c:3:9: error: ‘MAP_ANONYMOUS’ undeclared here (not in a function)
Whereas in Gnu99 mode, it does:
$ gcc -std=gnu99 -c d.c