Why is not compilation of literary tasks without casting

I have a question about literals in C.

int a;
//a is an integer that is assigned an integer literal 414
a = 414;

float b;
//b is a float that is assigned a float literal of 3.14
b = 3.14;

struct point {
    int x,y;
};

struct point b;
//{5,6} is a compound literal that is assigned to a struture.
b = {5,6}; //doesn't work.

b = (struct point){5,6}; //works.

Does this not work without type casting? What is the reason for this?

+4
source share
1 answer

(struct point){5,6} as a whole is a composite literal.

C11 §6.5.2.5 Compound literals

A postfix expression consisting of a type name in brackets followed by a bracket. The list of initializers is a composite literal.

+5
source

All Articles