Hi, I used to initialize my structures in this way:
struct A a = {0};
This seems to work for me, however I was argued about ANSI C, C89, C99 standard.
Simply I couldn't find that in any documentation.
Could you help me with that?
Here's an example that this works for 'cl' (VS express 2008).
#include <stdio.h>
struct DATA
{
int a;
int b;
char tab[3];
};
void main(void)
{
struct DATA A;
struct DATA B = {0};
printf("A.a: %d, A.b: %d, A.tab: %s\n", A.a, A.b, A.tab);
printf("B.a: %d, B.b: %d, B.tab: %s", B.a, B.b, B.tab);
};
>>>>>OUTPUT:
D:\N\workspace>test.exe
A.a: 4203600, A.b: 451445257, A.tab: ■
B.a: 0, B.b: 0, B.tab:
This one shows that it initialize first with 1, rest with 0's.
include <stdio.h>
#include <stdlib.h>
typedef struct {
int a;
int b;
} ASDF;
ASDF A = {1};
int main()
{
printf("a:%d,b:%d\n",A.a,A.b);
return 0;
}
Output:
a:1,b:0