|
楼主 |
发表于 2008-6-13 17:59:14
|
显示全部楼层
多谢了,但是有个问题,会出现段错误:
[duxiaoyu@hnchen ~]$ cat me.c
#include <stdio.h>
void print() __attribute__((__noreturn__));
void print()
{
printf("hello world\n");
}
struct my_struct
{
char c;
int i;
} __attribute__((__packed__));
int main()
{
struct my_struct a;
a.c= 1;
a.i =2;
printf("size is %d\n", sizeof(a));
print();
return 0;
}
[duxiaoyu@hnchen ~]$ gcc -o me me.c
me.c: In function ‘print’:
me.c:6: 警告:‘noreturn’ 函数确实会返回
[duxiaoyu@hnchen ~]$ ./me
size is 5
hello world
段错误
[duxiaoyu@hnchen ~]$
但这样没事:
[duxiaoyu@hnchen ~]$ cat me.c
#include <stdio.h>
void print() __attribute__((__noreturn__));
void print()
{
printf("hello world\n");
}
struct my_struct
{
char c;
int i;
} __attribute__((__packed__));
int main()
{
struct my_struct a;
a.c= 1;
a.i =2;
printf("size is %d\n", sizeof(a));
//print();
printf("hello world\n");
return 0;
}
[duxiaoyu@hnchen ~]$ gcc -o me me.c
me.c: In function ‘print’:
me.c:6: 警告:‘noreturn’ 函数确实会返回
[duxiaoyu@hnchen ~]$ ./me
size is 5
hello world
[duxiaoyu@hnchen ~]$
难道返回就出错了,高手指教了。 |
|