MAP_ANONYMOUS with C99 standard

孤街醉人 提交于 2020-01-01 07:33:08

问题


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


来源:https://stackoverflow.com/questions/5446698/map-anonymous-with-c99-standard

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!