Martin said:
Hello.
I am programming a program which includes many libraries I have programmed.
All libraries require this:
typedef short word;
But I get an error when I include this statement two times.
If I used #define instead, I could use #ifdef, but I cannot with typedefs
How can I solve this?
This is Question 10.15 in the comp.lang.c Frequently
Asked Questions (FAQ) list
http://www.eskimo.com/~scs/C-faq/top.html
.... which is somewhat surprising, since I can't recall the
last time I saw someone ask it. Also, the FAQ's answer,
while correct, is not very helpful. So here's an approach:
Presumably you've got a lot of .h files associated with
these libraries, and they all contain `typedef short word;'.
Try replacing it (everywhere) with something like
#ifndef WORD_HAS_BEEN_TYPEDEFED
typedef short word;
#define WORD_HAS_BEEN_TYPEDEFED
#endif
While you're about it, you might want to reconsider the
use of `word' as part of your libraries' public interfaces:
there's no visual signal that it means anything special or
that it "belongs" to your libraries, and it's a word that
some hapless victim might be using for his own purposes:
char line[] = "Hark! Hark! The lark at heavn's gate sings!";
char *word = line;
while ((word = strtok(word, " \t\n.,!?\"'")) != NULL) {
printf ("The next word is %s\n", word);
word = NULL;
}
You might use `MJword' instead, to suggest that the
identifier belongs to MJ's library. At the very least,
use `Word' to give a visual clue that the identifier is
in some way unusual.