incomplete type revisted

Tags:

[quote]
> But, opposed to my reasoning, g++ raise an error when above
> code is compiled. What’s the things that I don’t understand
> here?

I’m tempted to ask: what do you want to understand? The
compiler writers don’t seem to understand it, so why should
you:-)?

Seriously: put your extern’s and incomplete types at namespace
scope in a header file. Make sure that the header is included
before any definition, and you shouldn’t have any problems. As
for understanding… since it’s not at all clear what the
standard really says, the only solution is to join the committee
and help define it.
[/quote]

원문은 http://tinyurl.com/8v957 에..

가장 큰 문젠, 제가 질문한 경우와 같이 complete type이 먼저 나오고 incomple type이 나중에 나오는 경우에 대해 표준이 아무런 명시도 하지 않는다는 점 같네요. 링크내의 discussion을 다 이해하진 못하겠고 – 적어도 저는 자바 스펙은 다 읽어보았지만 C++ 스펙을 다 읽어본적은 없으니 – 어떻게든 how to 라도 건져야하는데..

결론적으로 인용문에도 나와있듯이, 1) 모든 incomplete type을 헤더에 넣고 complete type 이전에 컴파일러가 얘네들을 보게 해서 나중에 complete type이 되게 하거나, 2) class나 struct 는 어쩔 수 없겠지만 배열의 경우엔 항상 int a[] 대신 int *a 를 쓰는 것이 방법인 듯 싶습니다.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *