MAP_ANONYMOUS与C99标准 [英] MAP_ANONYMOUS with C99 standard

查看:176
本文介绍了MAP_ANONYMOUS与C99标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用mmap系统调用的应用程序,我在得到它的编译看,为什么我是越来越MAP_ANON和MAP_ANONYMOUS是未申报时间的问题,我不得不code的一小部分,我使用我看到我可以编译它只是罚款,所以我尝试只是一个基本的编译和工作,我看到,当您添加-std = C99失败。是否有一个具体的原因,MAP_ANON和MAP_ANONYMOUS是无效的C99标准?我知道他们不是POSIX定义,但通过BSD源代码的定义,所以我只是想知道这是为什么。

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.

推荐答案

您可能希望 -std = gnu99 而不是 -std = C99 。 C99模式明确禁用(大多数)GNU扩展。

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;

在C99模式下,它没有找到该值:

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)

而在Gnu99模式,它的作用:

Whereas in Gnu99 mode, it does:

$ gcc -std=gnu99 -c d.c

这篇关于MAP_ANONYMOUS与C99标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆