answersLogoWhite

0

Because otherwise the preprocessor would ignore them.

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

In C plus plus what sign do all preprocessor directives start with?

all preprocessor directives start with #(hash) symbol in both c & c++


What is the difference between preprocessor directives and header files?

Preprocessor: All the preprocessor commands written in a high level language are processed by the preprocessor before compiler takes over.Example: "#define MAX_ROWS 10"Preprocessor finds all the places and replaces MAX_ROWS with 10 in the files of the project.Compiler: This software, converts the code written in high-level language into object file. Compiler converts all the files of a given project at once.


What are preprocessor directives in c programing language?

Preprocessor directives are instructions to the preprocessor which modify the source code prior to compilation. The compiler never sees the directives, it only sees the modified source code. Preprocessor directives can be used to insert the contents of one file into another (#include), define or undefine a macro (#define, #undef), provide conditional compilation (#if, #ifdef, #ifndef, #else, #endif) or provide some implementation-defined operation (#pragma). When the preprocessor acts upon a directive, the directive is not included in the modified file. Where a directive defines a macro, all occurrences of the macro name within the source code are expanded according to the definition. Given that the compiler never sees that definition, this can lead to some obscure error messages where macro expansion results in a compile-time error.


How does c plus plus code compiled?

When you invoke the compiler, the preprocessor (also known as the precompiler) runs first to process all the precompiler directives and macros; the lines beginning with the pound symbol (#) such as #define and #include. The preprocessor also strips out all of the comments. The preprocessor achieves this by creating one or more temporary, intermediate files containing nothing but C++ code. The compiler then compiles these intermediate files into object code which the linker uses to create the final executable.


What is difference between using declarative method and using directive method?

The simple answer is that directives are symbols that instruct or direct the preprocessor, while declarations are C++ symbols that are processed by the C++ compiler. The preprocessor and the compiler are essentially two completely separate operations. The preprocessor is tasked with modifying your source files in order to produce temporary intermediate source files which the compiler can process more efficiently. These intermediate files contain nothing but C++ code, thus the preprocessor's primary job is to strip out all the comments from your source files. Preprocessor directives are used to instruct the preprocessor in all other modifications, such as where and when to include one file within another and which sections of code are valid for a particular build. This is achieved by #define directives, in conjunction with #ifdef, #else and #endif directives. The #define directive defines a symbol. As the preprocessor encounters these directives, the symbols are placed in a definition table, which includes all the symbols that were initially passed via the command line. Some symbols have no value assigned to them; their presence in the table is sufficient to know they are defined, and the preprocessor can simply act according to whether a symbol is currently defined or not. The #undef directive is the antidote to #define, allowing symbols to be undefined (removed from the table) by the preprocessor. However, #define can also be used to assign a value to a symbol. This value acts a text replacement for the symbol, thus wherever the symbol is encountered within your code (outwith any other directives), the symbol is replaced with the text value associated with that symbol. These are known as macros. #define can also be used to declare macro functions, where the text replacement includes one or more arguments within parenthesis, followed by C++ code that processes those arguments. Thus all occurrences of the symbol in your code must include an argument list with the same number of arguments as the macro directive. The preprocessor then inline expands the macro function, replacing its arguments with the formal arguments provided by your code. The problem with #define in general is that it is not a C++ statement, it is a macro, and macros are not subject to the strong-typing that is fundamental to C++. So while you can use #define to declare literal constants, those constants are untyped. Moreover, since the compiler never sees the macro definition (it is stripped from the intermediate file), any errors that occur as a result of a macro expansion cannot be sourced back to the macro, which makes debugging difficult at best. In the case of macro functions, the debugger cannot help you at all, you're completely on your own. Thus when you have the option to use directives or declarations, always go with a declaration. C++ code is type safe, can be easily debugged, is easier to maintain, and usually results in much smaller compiled code. Only use the preprocessor to generate code that would be difficult or impossible to generate with the compiler alone. In other words, use directives specifically to direct the preprocessor. Never rely on them to generate C++ code unless you have no other option, or it would greatly simplify a far more complex C++ implementation.


How do you implement c program for conditional compilation?

Conditional compilation is achieve through preprocessor directives. First, define the preprocessor symbols upon which conditional compilation depends, then test them using #if and #else preprocessor directives. A #endif directive indicates the end of the nearest enclosing conditional block, thus conditional blocks may be nested. The following example demonstrates how we can conditionally define debug or production code based upon the absence or existence of the NDEBUG symbol: #ifdef NDEBUG /* all C code within this block is compiled when NDEBUG is defined (production code) */ #else /* all C code within this block is compiled when NDEBUG is not defined (debug code) */ #endif Note that the NDEBUG symbol is typically defined via the command line, however symbols can also be defined or undefined via the source using the #define and #undefine directives. For instance, header files typically require guards to protect against being included more than once in a compilation and preprocessor directives provide the conventional means of ensuring that is the case: // myheader.h #ifndef _MYHEADER_H_ #define _MYHEADER_H_ // all header code goes here... #endif By convention, preprocessing symbols (macros) are defined with all uppercase and are intentionally ugly to avoid any confusion with C identifiers. Header guards must be unique to each header thus they are typically based upon the header file name itself.


What are preprocessor directives or statements?

For example:define a symbolundefine a symbolinclude another fileconditionally exclude/include partsetcAs the name suggests, a preprocessor directive modifies the source code before the compiler sees it. This way the developer can keep the logic at a high level while the compiler does all of the work. As an example:# define N 5if (TestingValue == N)is cleaner code and easier to change should the value for N change. It leads to better modular code for code maintainers.


What are compiler directives?

Compiler directives instruct the preprocessor to perform certain tasks prior to compiling the source code. The language compiler can only compile C code, but macros (lines beginning with a # symbol) are not part of the C language, so these need to be processed before the compiler can do its job. The most common compiler directive is the #include directive, which instructs the preprocessor to import the named file, effectively copy/pasting the content of that file in place of the directive. The content may itself contain directives and these must also be processed accordingly before the content is inserted. Note that the insertion takes place in a temporary file; the source file is not changed by the preprocessor. The temporary file is usually deleted after compilation is complete, however you can configure the compiler to retain these files so you can see what code is produced by the preprocessor and thus what the compiler "sees". The #define and #undefine compiler directives define or undefine macros; symbols which the preprocessor can refer to while processing other directives. Macros can also be defined via the command line. The #ifdef, #ifndef, #elif, #else and #endif compiler directives are used in conditional compilation in conjunction with macro definitions. These tell the preprocessor which parts of the source code to include in or exclude from the temporary file. This is useful when writing debug code that we wish to include in a debug build but exclude from a retail build, or we wish to cater for different architectures and require different libraries and function calls in order to cater for them. A macro symbol can also be given a value. Wherever that symbol appears in the code, the symbol is replaced with the value. This provides a convenient text-replacement system that can help make code easier to read. However, a macro can also be used to define a function (a macro function). These differ from ordinary functions in that they are always inline expanded, however they are not type-safe and the compiler cannot help you debug them (the compiler never sees the macro -- it only sees the inline expanded code produced by the macro). Macro functions are best avoided, however when used with care they can help to resolve complex problems that cannot easily be resolved within the language itself. It's best to think of macro functions as being code generators but, because they are not part of the language, its best to keep their usage as simple as possible. As well as processing compiler directives, the preprocessor also strips out all the user-comments from the source file. Even if a compiler could read a comment it certainly wouldn't understand it, so to keep the compiler implementation as simple and as efficient as possible, all non-C code is completely stripped out. Even the redundant whitespace and newline characters are stripped out. The end result is a compact source file which can be easily compiled -- assuming no errors have been generated by your macros!


Have your units open ranks and stack arms are all examples of?

Directives


What force do advanced medical directives carry?

All medical directives, whether the living will, power of attorney, or do not resuscitate order , are respected by all health personnel in whatever medical setting the chosen state stipulates.


What are preprocessor directive?

Preprocessor directives are used to mark code that is specific to a particular compiler and thus to a specific machine architecture. In this way, programmers can write cross-platform code in the same source and let the compiler decide which parts of the source to compile and which to ignore. In reality, the compiler never actually sees the preprocessor directives since the preprocessor creates new files containing only the code that is to be compiled. Hence the preprocessor is often called the precompiler. Normally, the intermediate source files are deleted as they are compiled, however your development environment should contain an option that allows you to view these files so you can see what the compiler actually works with. In C and C++, all preprocessor directives have a leading # symbol, such as #include and #define. #include is by far the most common preprocessor directive. When the precompiler encounters a #include statement, the named header file is essentially copy/pasted in place of the directive. However, all header files should also contain #ifndef header guards to ensure headers are only included once per compilation and these have to be preprocessed as well. Macro definitions are also preprocessed, replacing all instances of the macro symbol with the definition. Macro functions are also inline expanded but since the compiler only sees the expanded code, never the macro itself, the compiler cannot help you debug errant macros. This is why non-trivial macro functions are best avoided.


Which agency enforces all traffic rules and directives on the airfield?

Security Forces