- 论坛徽章:
- 0
|
今天在写程序的时候,无意中发现的,因为自己从来没有这么用过,也不是很清楚原因,所以把代码提炼了一下,请各位大侠帮忙解答~~分析一下原因!代码如下:
第一个:
#include <stdio.h>
static int a = 1;
static int b = a;
int main(){
printf("%d\n",b) ;
return 0;
}
在gcc下无法通过,在g++下编译通过~!
第二个:
#include <stdio.h>
typedef struct A{
int i;
char *a;
}A;
static char b = 'B';
static A a={
.i = 1,
.a = &b,
};
int main(){
printf("%c\n",*(a.a)) ;
return 0;
}
在gcc下编译通过,但是如果改成如下后,gcc又再次报错:
#include <stdio.h>
typedef struct A{
int i;
char a;
}A;
static char b = 'B';
static A a={
.i = 1,
.a = b,
};
int main(){
printf("%c\n",a.a) ;
return 0;
} |
|