Both MAP_ANON and MAP_ANONYMOUS undeclared for sys/mmap in C

c, memory, unix

Solution

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.

More information about GCC's language standards can be found here.

GCC also provides a very exhaustive list of exactly what extensions they provide here.

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`).

Problem

This is my `mman.h` file included from `/usr/include/sys/`: http://pastebin.com/FZpHwKMC 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 */ ``` I'm at a loss of what could be wrong. I'm compiling using this makefile: http://pastebin.com/R1V2edmf EDIT: It turns out the `MAP_ANONYMOUS` macro is defined in `/usr/include/bits/mman.h` but only if `__USE_MISC` is defined... Any help would be terrific!

Original source

Related problems