Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of a these #define within an enum?

Tags:

c

linux

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 DT_FIFO    DT_FIFO        DT_CHR = 2, # define DT_CHR     DT_CHR     DT_DIR = 4, # define DT_DIR     DT_DIR     DT_BLK = 6, # define DT_BLK     DT_BLK     DT_REG = 8, # define DT_REG     DT_REG     DT_LNK = 10, # define DT_LNK     DT_LNK     DT_SOCK = 12, # define DT_SOCK    DT_SOCK        DT_WHT = 14 # define DT_WHT     DT_WHT   };    

What is this construct for? - why define something with an identical string, which will then compile to the int value?

like image 888
GrahamW Avatar asked Dec 21 '11 10:12

GrahamW


People also ask

What is main purpose of thesis?

In general, a thesis statement expresses the purpose or main point of your essay. Additionally, the thesis may include the significance of or your opinion on this topic. It is your commitment to the reader about the content, purpose, and organization of your paper.

What are the 3 purposes of a thesis statement?

For you as the WRITER, the thesis statement: Narrows your writing to one specific claim that you can develop or prove; Organizes your ideas so you know the important points you want to make in your paper; and. Clarifies your writing by keeping you on target to fulfill your proposed purpose.

Why is the thesis the most important?

When you provide a strong thesis statement at the beginning of an essay, it tells the reader what the paper is going to be about right away. The reader will know what you're going to talk about and how you feel about the topic in question and this is a very important point.

What is the purpose of writing a thesis in college?

The thesis is one of the most important concepts in college expository writing. A thesis sentence focuses your ideas for the paper; it's your argument or insight or viewpoint crystallized into a single sentence that gives the reader your main idea.


2 Answers

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.

like image 113
Luchian Grigore Avatar answered Oct 02 '22 13:10

Luchian Grigore


My guess is that some other code can then check if one of (or more of) these enum values have been defined using #ifdef.

like image 26
Sebastiaan M Avatar answered Oct 02 '22 15:10

Sebastiaan M