Preprocessors: #pragma



A compiler of one particular programming environment has characteristics that distinguish it from other compilers. To customize its behavior, some instructions can tell it how to behavior and how to treat some code sections when it encounters them. One of the instructions used by a programming to direct a compiler is done using the #pragma preprocessor. It is used to give specific instructions to the compiler based on the particular compiler that is being used to create the program. This means the #pragma directive completely depends on the compiler you are using.

Open Once

When you create a file for your project as we saw in the previous lesson, when the compiler is building the project, you can instruct it to open a certain file only once, during the lifetime of the program. This has the role of reducing the overhead of over and over checking again if the file has already been opened. To give this instruction, you should start the file with

#pragma once

Under this line, you can then include the rest of the lines of code for the file.




Home Copyright © 2006-2016, FunctionX, Inc.