#include<stdio.h>
#define STORAGESIZE 5
#define MAX_NAME_LEN 2
typedef struct{
char name[MAX_NAME_LEN];
char feild1;
char feild2;
} strt;
static strt storage[5];
main(){
unsigned char *stp=(unsigned char*)&strt;
unsigned char*stp_end=(unsigned char*)(&strt+STORAGESIZE);
int i;
for(i=0;stp!=stp_end;stp++,i++)
printf("byte%d: %x\n",i,*stp);
}
정적으로 선언 된 구조체는 모두 패딩 부분을 제외하고 0으로 초기화된다는 것을 확인하려고합니다. statictable.c : 위를 컴파일 할 때 와 나는 오류를 가지고
{aStructName} 전에 예상되는 표현식이
In function 'main':
statictable.c:13:38: error: expected expression before 'strt'
statictable.c:14:42: error: expected expression before 'strt'
아마도 나는이 밝혀 질 수 알고 다른 pointer.Although에 주조 포인터의 할당에 잘못 될 수 무엇 초보적이다. 라인에서
항상 main()에 대해 반환 유형 ('int')을 지정하십시오. C99 (및 C11)에서 필요합니다. C99에서는이를 생략하고 0을 반환하지만 C89에서는 반환 값을 생략 할 수 없지만 프로그램에서 값 (성공한 경우 0)을 반환하는 것이 가장 좋습니다. 당신은 두 가지 방법 모두 가질 수 없습니다. –