可以-std = C99 prevent我#包括正常工作? [英] Can -std=c99 prevent my #includes from working properly?

查看:198
本文介绍了可以-std = C99 prevent我#包括正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译Linux系统上的C程序。我有一个的#include 语句文件stdlib.h

当我编译程序与 GCC 如下:

 的gcc -std = C99 -g -o progfoo progfoo.c progbar.c

我得到关于警告的功能[srand48,drand48,bzero或接近]隐式声明

而不是编译如下:

 的gcc -o -g progfoo progfoo.c progbar.c

不给我的警告,但它确实喊我的使用循环(这是理加入 -std = C99 在首位)。

由于男人srand48 中提到,包括<文件stdlib.h> ,这是我,我不能确定这个问题可能是什么。在循环是不是什么必不可少的(他们只是为了节省时间初始化数组),所以我没有问题,删除他们,但我做之前,我想确认 C99 标准是否被取代我的的#include 语句的某些方面。

我用 GCC 4.1.2-50(红帽)


解决方案

  

能否-std = C99 prevent我#包括正常工作?


没有,但他们可能会出现在你的知识的限制,它们是如何工作: - )


虽然功能 [SD] rand48 文件stdlib.h 原型,他们内部的 #IFDEF ,至少在我的系统:

 #如果定义__USE_SVID ||定义__USE_XOPEN

所以,你可能要明确设置这些宏之一。

不过,你在尝试之前,要知道,这是行不通的。这是因为所有这些东西与 GCC的功能测试宏的。

有一个非常复杂的一套用于设置特定功能的 features.h 开或关的规则,创造有宏控制一下头文件包括和排除。在 __ USE _ * 的变种被清除,并基于该头文件中设置的其他的自己提供的宏。

例如,要获得 __ USE_SVID 设定 srand48 ,您需要提供一个编译器,你可以使用 -D_SVID_SOURCE 参数。

但也许是一个更简单的方法是只使用C99和GNU扩展。要做到这一点,将 -std = C99 -std = gnu99

和,为 bzero 关闭,这些都可以从 strings.h获得 unistd.h中分别。

我是一个有点困惑首先,为什么这些编译 -std = C99 时,他们有绝对的没有的做,但C99后来我意识到,标志仅控制什么的标准C头文件的给你。

无论是 strings.h (注意是复数名字,这是的文件string.h ),也不 unistd.h中是ISO C的一部分。

I am trying to compile a C program on a Linux system. I have an #include statement for stdlib.h.

When I compile the program with gcc as follows:

gcc -std=c99 -g -o progfoo progfoo.c progbar.c

I get warnings about Implicit declaration of function [srand48, drand48, bzero, or close].

Compiling instead as:

gcc -g -o progfoo progfoo.c progbar.c

doesn't give me the warnings, but it does yell about my use of for loops (which was the rationale for adding -std=c99 in the first place).

Given that man srand48 mentions including <stdlib.h>, which I have, I'm unsure what else the problem could be. The for loops aren't essential to anything (they were just to save time in initializing an array) so I have no problem removing them, but before I do I'd like to confirm whether the c99 standard is superseding some aspect of my #include statements.

I'm using gcc 4.1.2-50 (Red Hat).

解决方案

Can -std=c99 prevent my #includes from working properly?

No, but they may show up limitations in your knowledge of how they work :-)


While the functions [sd]rand48 have a prototype in stdlib.h, they're inside an #ifdef, at least on my system:

#if defined __USE_SVID || defined __USE_XOPEN

So you will probably have to explicitly set one of those macros.

However, before you try it, be aware that it doesn't work. That's because all this stuff is controlled with gcc's feature test macros.

There's a very complicated set of rules used to set specific features on or off in features.h and the macros created there control what the header files include and exclude. The __USE_* variants are cleared and set in that header file based on other macros provided by yourself.

For example, to get __USE_SVID set so you can use srand48, you need to provide the compiler with a -D_SVID_SOURCE parameter.

But perhaps an easier way is to just use C99 with the GNU extensions. To do that, replace -std=c99 with -std=gnu99.

And, for bzero and close, these can be obtained from strings.h and unistd.h respectively.

I was a little confused at first as to why these compiled with -std=c99 when they have absolutely nothing to do with C99 but then I realised that flag only controls what the standard C headers give you.

Neither strings.h (note the plural name, this is not string.h) nor unistd.h are part of ISO C.

这篇关于可以-std = C99 prevent我#包括正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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