Preprocessor Directives in C Program
-
What is the role of preprocessor directives in c program? What if, we don't use it?
-
What is the role of preprocessor directives in c program? What if, we don't use it?
Preprocessor are executed before compilation. This is a macro processor, which is used automatically by the C compiler to transform your program before actual compilation.
In simple words, preprocessor directives tells the compiler to preprocess the source code before compiling. All the preprocessor commands are begin with "#" symbol.
The most common use of the preprocessor is to include header files. In C and C++, all symbols must be declared in a file before they can used. They don’t always need to be defined*, but the compiler needs to know they exist somewhere. A preprocessor is just another technique to help a programming language be more useful. There are numerous techniques available and every language designer must choose the ones they like.
-
What is the role of preprocessor directives in c program? What if, we don't use it?
-
What is the role of preprocessor directives in c program? What if, we don't use it?
You don't have to use Preprocessor Directives it is entirely up to you they are there to make life easy and are not mandatory at all. Here is a hello world without a single Preprocessor Directive :-)
#include
int main (void)
{
printf("hello world\n");
return 0;
}No Preprocessor Directive was harmed in the making of that code.
In vino veritas
-
You don't have to use Preprocessor Directives it is entirely up to you they are there to make life easy and are not mandatory at all. Here is a hello world without a single Preprocessor Directive :-)
#include
int main (void)
{
printf("hello world\n");
return 0;
}No Preprocessor Directive was harmed in the making of that code.
In vino veritas
-
Umm ... I think you could argue that
#include
is, indeed a preprocessor directive. It does, after all tell the pre-processor to include the given file as part of the source text passed to the compiler.haha true ... lets try that again
int main (void)
{
volatile int i = 0;
i = i++;
}Even stopped it optimizing away :-)
In vino veritas
-
haha true ... lets try that again
int main (void)
{
volatile int i = 0;
i = i++;
}Even stopped it optimizing away :-)
In vino veritas
leon de boer wrote:
Even stopped it optimizing away
but atill doesn't return the
int
it declares it will. ;PSoftware rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
-
leon de boer wrote:
Even stopped it optimizing away
but atill doesn't return the
int
it declares it will. ;PSoftware rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
Hey it was late only a cup of coffee between good code and bad code !!! You are right I say return 0 to you :-)
In vino veritas
-
You don't have to use Preprocessor Directives it is entirely up to you they are there to make life easy and are not mandatory at all. Here is a hello world without a single Preprocessor Directive :-)
#include
int main (void)
{
printf("hello world\n");
return 0;
}No Preprocessor Directive was harmed in the making of that code.
In vino veritas