Suppose there is such a code:
typedef int i32; How to find out if i32 type i32 already been announced? That is, something like #ifdef for typedef only.
Do not know.
If the far-sighted author of the code foresees the need for such verification in the future, he usually accompanies the definitions of types with the definition of additional macro. For example, the standard header file <stdbool.h> contains the macro definition __bool_true_false_are_defined with a value of 1 .
There is a double compilation method, I know how to do this in Linux through a Makefile . First a simple file is compiled with typedef . The compilation error code is then checked, and #define TYPEREDEFINIED .
Makefile : main.o : main.c main.h ..TAB..: if gcc checktypedef.c &> /dev/null ; then ; else OPTIONFORGCC = -DTYPEREDEFINIED ; fi ..TAB..: gcc OPTIONFORGCC main.c .. checktypedef.c : # include <все заголовки из main> typedef unsigned char BYTE ; main.c : # include <все заголовки> # ifdef TYPEREDEFINIED # error Опять! # endif It is possible to declare all used header in one test.c file test.c for example, then:
gcc -E test.c | grep "int32my" and see the result :)
Source: https://ru.stackoverflow.com/questions/837365/
All Articles
-Wtypedef-redefinition. - VTT