C99中的struct [英] struct in C99
问题描述
大家好,
使用-std = c99强制执行gcc中的c99标准我得到:
$ gcc -Wall -std = c99 timespec .c
timespec.c:在函数''main''中:
timespec.c:5:错误:'a''的存储大小isn''t已知
timespec.c:5:错误:b的存储空间大小不知道
....
with:
#include< time.h>
#include< stdio.h>
int main(){
struct timespec a,b;
printf(" Doh!\ n") ;
返回0;
}
有人可以解释原因吗?这在以前的
版本的C中都不会发生。
干杯,
Paulo Matos
Hi all,
Using -std=c99 to enforce the c99 standard in gcc I get:
$ gcc -Wall -std=c99 timespec.c
timespec.c: In function ''main'':
timespec.c:5: error: storage size of ''a'' isn''t known
timespec.c:5: error: storage size of ''b'' isn''t known
....
with:
#include <time.h>
#include <stdio.h>
int main() {
struct timespec a, b;
printf("Doh!\n");
return 0;
}
Can someone please explain why? This doesn''t happen in previous
versions of C.
Cheers,
Paulo Matos
推荐答案
gcc -Wall -std = c99 timespec.c
timespec.c:在函数''main '':
timespec.c:5:错误:a的存储空间大小不知道
timespec.c:5:错误:存储大小''b''不知道
....
with:
# include< time.h>
#include< stdio.h>
int main(){
struct timespec a,b;
printf(" Doh!\ n");
返回0;
}
有人可以解释原因吗?这在以前的
版本的C中都不会发生。
干杯,
Paulo Matos
gcc -Wall -std=c99 timespec.c
timespec.c: In function ''main'':
timespec.c:5: error: storage size of ''a'' isn''t known
timespec.c:5: error: storage size of ''b'' isn''t known
....
with:
#include <time.h>
#include <stdio.h>
int main() {
struct timespec a, b;
printf("Doh!\n");
return 0;
}
Can someone please explain why? This doesn''t happen in previous
versions of C.
Cheers,
Paulo Matos
po ****** @ gmail.com schrieb:
大家好,
使用-std = c99强制执行gcc中的c99标准我得到:
注意:gcc仍然不完全是C99编译器,请参阅
http:// gcc.gnu.org/C99status.html
Hi all,
Using -std=c99 to enforce the c99 standard in gcc I get:
Note: gcc still is not entirely a C99 compiler, see
http://gcc.gnu.org/C99status.html
gcc -Wall -std = c99 timespec.c
使用gcc -Wall -std = c99 -pedantic -O timespec.c获取更多
警告并拒绝更多非标准C内容。
timespec.c:在函数中''main'':
timespec.c:5:错误:'a'的存储大小不知道
timespec.c:5:错误:存储大小''b' '不知道
用:
#include< time.h>
#in clude< stdio.h>
int main(){
struct timespec a,b;
注意:< stdio.h>也不是< time.h>保证定义
类型struct timespec。这个类型_probably_来自你的
< sys / types.h>并且似乎没有被std选项调用的其他
模式正确排除。
简而言之:编译器正确地为-std = c99但是应该
也适合-std = c89 ......
可能需要
#include< sys / types.h> < br $>
或
#define FOO
其中FOO管辖某些部分或整个
sys / types。 h被处理/包括在内。这是实现
具体,因此在这里偏离主题。
这取决于使用的gcc和glib版本,所以你有
在一个处理gcc或你的操作系统的新闻组中询问
a完整/好答案。
printf(Doh!\\ \\ n;
返回0;
}
有人可以解释一下原因吗?这在以前的版本的C中都不会发生。
gcc -Wall -std=c99 timespec.c
Use gcc -Wall -std=c99 -pedantic -O timespec.c to get more
warnings and refuse more non-Standard C stuff.
timespec.c: In function ''main'':
timespec.c:5: error: storage size of ''a'' isn''t known
timespec.c:5: error: storage size of ''b'' isn''t known
...
with:
#include <time.h>
#include <stdio.h>
int main() {
struct timespec a, b;
Note: Neither <stdio.h> nor <time.h> is guaranteed to define the
type struct timespec. This type _probably_ comes from your
<sys/types.h> and seems to be not excluded properly for other
modes invoked by the std option.
In short: The compiler gets it right for -std=c99 but should
get it right for -std=c89 as well...
It may be necessary to
#include <sys/types.h>
or to
#define FOO
where FOO governs whether certain parts or the whole of
sys/types.h are processed/included. This is implementation
specific and thus off-topic round here.
It depends on the gcc and glib versions in use, so you have
to ask in a newsgroup dealing with either gcc or your OS to get
a complete/good answer.
printf("Doh!\n");
return 0;
}
Can someone please explain why? This doesn''t happen in previous
versions of C.
注意默认情况下gcc用-std = gnu89编译,这是C90
加上GNU扩展 - 这种语言和它的库包含
的东西普通标准C(在C90,C95或C99品种中)确实没有.b $ b没有。
干杯
Michael
-
电子邮件:我的是/ at / gmx / dot / de address。
Note that gcc by default compiles with -std=gnu89 which is C90
plus GNU extensions -- this language and its library contain
stuff plain standard C (in the C90, C95, or C99 variety) does
not have.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
这篇关于C99中的struct的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!