1

Some C include files uses following convention:

typedef struct YOUSHALLNOTUSETHISNAME
    {
//  members
    } USETHISNAME;

How should I the predeclare USETHISNAME in this case? Break the convention and say

typedef struct YOUSHALLNOTUSETHISNAME USETHISNAME;

The problem is that I cannot control the header defining the struct. And I do not want to include the header defining the struct, since in this case it is a real beast: windows.h

Note:

This question is closely related to Forward declare FILE *.

Community
  • 1
  • 1
user877329
  • 6,717
  • 8
  • 46
  • 88
  • That seems fine: you're using the not-to-be-used name once only, and inside (presumably) the same header file, so it won't be used anywhere outside that header file anyway. It's the latter that's really the purpose. –  Jan 06 '15 at 10:14

1 Answers1

0

Improving on Gopi's deleted answer:

 typedef struct YOUSHALLNOTUSETHISNAME {
   // some fields
 } USETHISNAME;
 #define YOUSHALLNOTUSETHISNAME %%%some@thing!bad$for*the^C%compiler

Then most further occurrences of YOUSHALLNOTUSETHISNAME would be rejected, but a naughty developer could still later:

 #undef YOUSHALLNOTUSETHISNAME

BTW, if you don't want to define the fields of struct YOUSHALLNOTUSETHISNAME (which should be provided by another header) you could just

  typedef struct YOUSHALLNOTUSETHISNAME USETHISNAME;

Also, are you sure to want to avoid #include <windows.h>? Maybe you just need precompiled headers. Some compilers provide that feature.


However, I believe it is more a social issue than only a technical one. You should document that people should not use YOUSHALLNOTUSETHISNAME

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • This answer applies if I were the author of the header. But I am not, and I commit an error when I using the internal name. – user877329 Jan 06 '15 at 10:57