I found this code in the linux headers, /usr/include/dirent.h:
enum
{
DT_UNKNOWN = 0,
# define DT_UNKNOWN DT_UNKNOWN
DT_FIFO = 1,
# define D
I think that Luchian Grigore's answer was correct.
Code without defines:
#include <stdio.h>
// Defined somewhere in headers
#define DT_UNKNOWN 0
enum
{
DT_UNKNOWN = 0,
DT_FIFO = 1,
};
int main(int argc, char **argv)
{
printf("DT_UNKNOWN is %d\n", DT_UNKNOWN);
return 0;
}
From the compiler's output it is unclear why some line of code inside enum doesn't want to build:
alexander@ubuntu-10:~/tmp$ gcc -Wall ./main.c
./main.c:7: error: expected identifier before numeric constant
After we add such defines:
#include <stdio.h>
// Defined somewhere in headers
#define DT_UNKNOWN 0
enum
{
DT_UNKNOWN = 0,
# define DT_UNKNOWN DT_UNKNOWN
DT_FIFO = 1,
# define DT_FIFO DT_FIFO
};
int main(int argc, char **argv)
{
printf("DT_UNKNOWN is %d\n", DT_UNKNOWN);
return 0;
}
Compiler would tell us that DT_UNKNOWN is redefined and a place where it is redefined:
alexander@ubuntu-10:~/tmp$ gcc -Wall ./main2.c
./main2.c:7: error: expected identifier before numeric constant
./main2.c:8:1: warning: "DT_UNKNOWN" redefined
./main2.c:3:1: warning: this is the location of the previous definition
Besides the other answers which are very good - I would go with them for the main reason - the compiler could generate warnings or errors if you try to redefine DT_UNKNOWN
.
My (uneducated) guess is that the #define
statements allow conditional tests to see if the constant has been defined.
For example:
#ifdef DT_UNKNOWN
// do something
#endif
My guess is that some other code can then check if one of (or more of) these enum values have been defined using #ifdef.
I used -E
and -dD
arguments (and also -fdump-tree-all
) in gcc
to see the preprocessor output and found nothing useful. So I guess this code does not have any functionality other than perhaps displaying the symbolic names when debugging using a debugger like gdb
.