无论MAP_ANON和MAP_ANONYMOUS未声明在C SYS / MMAP [英] Both MAP_ANON and MAP_ANONYMOUS undeclared for sys/mmap in C
问题描述
这是从的/ usr / include / sys中/
包括我的 mman.h
文件:
不知怎的的mmap()
似乎被定义(可与标志0被使用和读/写保护),而不是 MAP_ANON
或 MAP_ANONYMOUS
如下所示:
Somehow mmap()
seems to be defined (and can be used with flags 0 and read/write protection), but not MAP_ANON
or MAP_ANONYMOUS
as indicated below:
#include <sys/mman.h>
int a = MAP_ANON; /* compile error */
int b = MAP_ANONYMOUS; /* also compile error */
我在什么可能是错误的亏损。我用这个makefile编译:
I'm at a loss of what could be wrong. I'm compiling using this makefile:
编辑:原来, MAP_ANONYMOUS
宏在 /usr/include/bits/mman.h
定义但仅如果 __ USE_MISC
定义...
It turns out the MAP_ANONYMOUS
macro is defined in /usr/include/bits/mman.h
but only if __USE_MISC
is defined...
任何帮助就太棒了!
推荐答案
如果你使用GCC,为此发生常见的原因是,你不使用GNU C标准。试着用编译,例如 -std = gnu11
,看看是否能解决问题。
If you're using GCC, a common reason for this to occur is that you're not using a GNU C standard. Try compiling with, e.g., -std=gnu11
, and see if that fixes the problem.
有关GCC的语言标准的详细信息,可以发现 rel=\"nofollow\">。
More information about GCC's language standards can be found here.
GCC还提供了他们提供的正是扩展的非常详尽的列表的这里。
GCC also provides a very exhaustive list of exactly what extensions they provide here.
此外,作为一个侧面说明,它是preferrable使用 MAP_ANONYMOUS
而不是 MAP_ANON
,作为后者是德precated(据男人MMAP
)。
Also, as a side note, it's preferrable to use MAP_ANONYMOUS
instead of MAP_ANON
, as the latter is deprecated (according to man mmap
).
这篇关于无论MAP_ANON和MAP_ANONYMOUS未声明在C SYS / MMAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!