Skip to main content
Better formatting, added missing “struct” keyword, used 42 as the int value (less likely to be there by default), added reference to GCC docs about obsolescence of this syntax
Source Link
Palec
  • 13.7k
  • 8
  • 79
  • 145

When I read some source code, I found a newanother way to initialize structs.

The struct as follow:

typedef struct test {
    int num;
    char* str;
} test;

typedef test{ int num;
char* str;
}test; Initialization:

test tt=tt = {
    num:0 42,
    str: "nice"
};

As per GCC’s documentation, this syntax is obsolete since GCC 2.5.

When I read some source code, I found a new way to initialize struct as follow:

typedef test{ int num;
char* str;
}test;

test tt={
num:0,
str:"nice"
};

I found another way to initialize structs.

The struct:

typedef struct test {
    int num;
    char* str;
} test;

Initialization:

test tt = {
    num: 42,
    str: "nice"
};

As per GCC’s documentation, this syntax is obsolete since GCC 2.5.

Source Link
4t8dds
  • 671
  • 9
  • 21

When I read some source code, I found a new way to initialize struct as follow:

typedef test{ int num;
char* str;
}test;

test tt={
num:0,
str:"nice"
};