#pragma

From RAD Studio
Jump to: navigation, search

Go Up to Pragma Directives Overview Index


Syntax

#pragma directive-name

Description

With #pragma, you can set compiler directives in your source code, without interfering with other compilers that also support #pragma. If the compiler doesn't recognize directive-name, it ignores the #pragma directive without any error or warning message.

C++Builder supports the following #pragma directives:


Directive Description Classic Compiler Clang Compiler
#pragma comment Writes a comment record in the object file. This can include linking to a library module. See Auto Linking for more information.
Allowed.png
Allowed.png
#pragma link Instructs the linker to link the file into an executable file. See Auto Linking for more information.
Allowed.png
Allowed.png
#pragma exit Indicates a function to be run on program exit (before _exit).
Allowed.png
Allowed.png
#pragma message Prints the specified message at compile time.
Allowed.png
Allowed.png
#pragma package Controls the initialization order of packages and other aspects related to packages.
Allowed.png
Allowed.png
#pragma resource Emits a comment record that instructs the linker to mark the file as a form unit.
Allowed.png
Allowed.png
#pragma startup Indicates a function to be run on program startup (before main).
Allowed.png
Allowed.png
#pragma alias Indicates that two identifier names are equivalent.
Allowed.png
#pragma alignment Prints the alignment setting and enum size.
Allowed.png
#pragma anon_struct Allows compiling anonymous structures.
Allowed.png
#pragma argsused Inhibits warning about unused arguments.
Allowed.png
#pragma checkoption Verifies that the specified options are set.
Allowed.png
#pragma codeseg Indicates the code segment for function allocation.
Allowed.png
#pragma codestring Emits bytes into the code segment.
Allowed.png
#pragma defineonoption Defines the specified symbol if the specified options are set.
Allowed.png
#pragma delphiheader Indicates the bounds of a Delphi header.
Allowed.png
#pragma explicit_rtti Specifies for what class or record members (public, protected, and so on) RTTI should be generated.
Allowed.png
#pragma extref Forces an external reference for the specified symbol.
Allowed.png
#pragma hdrfile Specifies the name of the precompiled header.
Allowed.png
#pragma hdrignore Obsolete.
#pragma hdrstop Stops the precompiling after the current header.
Allowed.png
#pragma implements Emits a comment record containing the name of the current unit to the object file.
Allowed.png
#pragma init_seg Affects the order in which startup code is executed.
Allowed.png
#pragma inline Causes the compiler to restart itself with the option -B.
Allowed.png
#pragma intrinsic Overrides the options that control the inlining of functions.
Allowed.png
#pragma nopushoptwarn Suppresses the warnings about mismatched #pragma option push/pop.
Allowed.png
#pragma nopackwarning Suppresses the warnings about mismatched #pragma pack push/pop.
Allowed.png
#pragma noretval Indicates that a function doesn't return.
Allowed.png
#pragma obsolete Indicates that the specified symbol is obsolete.
Allowed.png
#pragma once Indicates that the current header file must be included once.
Allowed.png
#pragma option Saves the current options and sets the specified options.
Allowed.png
#pragma pack Sets the structure packing alignment.
Allowed.png
#pragma region/end_region Indicates code regions. Used by the IDE editor for code folding.
Allowed.png
#pragma samecodeseg Places the specified functions in the same code segment.
Allowed.png
#pragma sizeof Prints the size of the specified aggregate.
Allowed.png
#pragma sysheader Indicates the bounds of a system header.
Allowed.png
#pragma undefineonoption Undefines the specified symbol if the specified options are set.
Allowed.png
#pragma warn Enables/disables warnings.
Allowed.png


Note: For many of the #pragma directives supported only by the Classic compiler, the Clang compiler silently accepts them but does not actually do anything.
Attention: #pragma comment (lib, "...") and #pragma link "..." both enable Auto-Linking.

They differ in the default extension when none is specified. It is important to note that the logic only supports short extensions: i.e. extensions of 3 letters or less.

When no extension is specified #pragma link "..." defaults to .obj and .o for WIN32 and WIN64 respectively. #pragma comment(lib, "...") defaults to .lib and .a for WIN32 and WIN64 respectively.
Note: To view all Clang pragmas see Clang's Compiler User Manual.