1

Considering the following definition:

struct
{
    int x;
    int y;
} point;


void main()
{ 
    ...
}

You're declaring the variable "point" of "anonymous struct" type, is there any way to declare another variable of the same type outside the struct definition (maybe in main function)?

4

3 回答 3

2

No, there isn't, at least not in standard C. If you want to use the type, you have to give it a name.

于 2013-05-23T23:28:25.510 回答
2

In standard C? No, you can't do that. But there are compiler extensions:

typeof(point) myPoint;

in clang and GCC, for example.

Editorial note: main() should return int.

于 2013-05-23T23:29:12.293 回答
0

Not too sure what you're asking, maybe:

void main()
{ 
    point p;
}

Also see http://www.cs.usfca.edu/~wolber/SoftwareDev/C/CStructs.htm

于 2013-05-23T23:29:46.023 回答