Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why struct tags are not type names in C? [closed]

Tags:

c

I am curious about the motivation for this behavior in C. Was it intentional or an accident?

struct tpoint // tpoint is not a type name
{
    int x, y;
};

typedef struct tpoint Point; // point is a type name.

I want to know why Ritchie or the standard committee chose this behaviour.

like image 233
Rayniery Avatar asked Mar 25 '13 22:03

Rayniery


1 Answers

It's a namespacing thing. This way, I can have struct a, enum a, union a, and none of them are ambiguous. It helps when designing frameworks which may have similar type names, but it can get confusing fast.

like image 126
Richard J. Ross III Avatar answered Oct 18 '22 14:10

Richard J. Ross III