Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#ifdef #else #endif macro question

I am new to C, and I am maintaining someones code. I came across this in the header file. I can understand that if the source is compiled on the windows it will enter the if statement else if the code is compiled on a linux it will enter the else statement. Correct me if I am wrong.

However, the question is why is # (hash) used in front of all the include headers?

Many thanks for any suggestions,

#ifdef WIN32
#   include <conio.h>
#   include <process.h>
#   include <stdlib.h>
#   include <string.h>
#else
#   include <unistd.h>
#   include <termio.h>
#   include <sys/types.h>
#   include <sys/stat.h>
#   include <fcntl.h>
#endif
like image 860
ant2009 Avatar asked Jul 17 '26 00:07

ant2009


1 Answers

The hash (#) indicates a preprocessor directive. The preprocessor runs over the code before compilation and does things depending on all the lines beginning with "#". The "#include filename.h" directive essentially copies all the contents of filename.h and pastes it where the "#include filename.h" line was.

like image 131
Tom Dalling Avatar answered Jul 21 '26 06:07

Tom Dalling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!