![]() |
VOOZH | about |
Pragma Directives: The pragma directive is used to control the actions of the compiler in a particular portion of a program without affecting the program as a whole.
Syntax:
#pragma string
Here, the string can be one of the instructions given to the compiler with any required parameters.
| Instruction | Description |
|---|---|
| COPYRIGHT | To specify a copyright string |
| COPYRIGHT_DATE | To specify a copyright date for the copyright string |
| OPTIMIZE | To turn the optimization feature on or off |
| LOCALITY | To name a coded subspace |
| OPT_LEVEL | To set the level of optimization |
| HP_SHLIB_VERSION | To create a version of a shared library routine |
| VERSION ID | To specify a version string |
| ONCE | Specify that file opened only once |
:
The syntax of pragma copyright is:
#pragma copyright "string"
Example: If copy write is written in a below way:
#pragma copyright "GFG Private Limited"
© Copyright GFG private limited, 2020.
All rights reserved. No part of this program may be copied, reproduced, or transmitted without the prior written consent of GFG Private Limited.
Note: To see the COPYRIGHT string as well as any other strings in the object file, use the strings(1) command with the -a option.
Example:
strings -a ObjectFileName.o
The syntax of pragma copyrighted is:
#pragma COPYRIGHT_DATE "string"
Here, the string is a date that will be used by the COPYRIGHT pragma.
Consider the following example given below:
#pragma COPYRIGHT_DATE "2011-2020"
#pragma copyright "GFG Private Limited"
The above pragma will place the following string in the object code:
© Copyright GFG Private Limited, 2011-2020.
All right reserved no part of this program may be photocopied reproduced, or transmitted without the prior written consent of GFG private limited.
Note: To see the COPYRIGHT_DATE string as well as any other strings in the object file, use the strings(1) command with the -a option.
Example:
strings -a ObjectFileName.o
The syntax of pragma OPT_LEVEL which is used to set the optimization level to 1, 2, 3 or 4 is:
# pragma OPT_LEVEL 1
# pragma OPT_LEVEL 2
# pragma OPT_LEVEL 3
# pragma OPT_LEVEL 4
Like the optimization pragma, even the pragma cannot be used in a function. Finally, OPT_LEVEL 3 and 4 are allowed only at the beginning of the file.
Below is an example code snippet in C illustrating the use of pragma opt level:
The syntax of using the pragma OPTIMIZE is:
#pragma OPTIMIZE ON
#pragma OPTIMIZE OFF
Below is an example code snippet in C illustrating the use of optimization pragma:
The syntax for HP_SHLIB_VERSION which is used to create different versions of shared library routine is:
#pragma HP_SHLIB_VERSION ["]date["]
Example:
#pragma HP_SHLIB_VERSION ["]12/20["]
The syntax of pragma locality which is used to specify the name to be associated with the code that is written to a relocatable object module is:
#pragma LOCALITY "string"
Example:
#pragma LOCALITY "Geeks For Geeks"
The syntax of pragma VERSION ID can be given as:
#pragma VERSIONID "string"
Here string is a string of characters that is placed in the object file.
Example:
#pragma VERSIONID "GFG private limited, Version 1234 5.8.0 1.10"
In the above example, the pragma places the character geeks for GFG private limited, Version 1234 5.8.0 1.10 into the object file.
The pragma once specifies that the file in which this pragma directory is specified will be included opened only once by the compiler in a building of a particular file it's syntax can be given as:
#pragma once
Conclusion: