Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MAP_ANONYMOUS with C99 standard

Tags:

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.

like image 209
Jesus Ramos Avatar asked Mar 27 '11 01:03

Jesus Ramos


1 Answers

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
like image 111
Conrad Meyer Avatar answered Sep 25 '22 19:09

Conrad Meyer