Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1310
  • Last Modified:

#pragma usage

Can someone explain with a simple example the usage of
#pragma directive.

Thanks,
Arut
0
arut
Asked:
arut
1 Solution
 
rajeev_devinCommented:
#pragma inline_depth( [0... 255] )

Controls the number of times inline expansion can occur by controlling the number of times that a series of function calls can be expanded (from 0 to 255 times).
0
 
rajeev_devinCommented:
Another example:

#if _M_IX86 == 500
#pragma message( "Pentium processor build" )
#endif

This will generate the message "pentium processor build", if your processor is a pentium one.
0
 
arutAuthor Commented:
Is inline_depth a macro understood by a compiler?

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
bharat_maneCommented:
0
 
rajeev_devinCommented:
yes its' a kind of macro.
0
 
Kent OlsenData Warehouse Architect / DBACommented:

In the MicroSoft URL mentioned above, take particular note of the opening paragrpah's last line, "Pragmas are machine- or operating system-specific by definition, and are usually different for every compiler."

This means that a #pragma statement that works just fine with your MicroSoft compiler may fail with Borland, gcc, or any other compiler.  (The inverse is also true.)

The standard states that unknown pragma directives are ignored.  The intent is that, since #pragma directives are meant to control machine-specific characteristics, they will be ignored on other platforms.  The byproduct is that the program might easily compile when ported to another system, but there is no assurance that it will run.

Often, the default characteristic of a C/C++ "struct" is that items contained within the struct are word aligned for speed.  If you want the items byte aligned, you include the correct #pragma directive.

#pragma align=b
#pragma align=byte

is a perfectly valid pragma statement.  Any system that uses the "align" parameter to control data alignment will pack all subsequent definitions so that they occupy the least amount of space.  But not all systems use "align" for this parameter.  If compiled on one of these systems, the compiler will parse the statement, recognize that "align" is not in its repertoire, an continue without affecting the rest of the compilation.

#pragma pack

is used in other environments.  So you have to know which one is appropriate for your system.  You could play it safe and include both.

Unknown parameters are supposed to be ignored.  Illegal parameters are errors.

#pragma align=byte
#pragma align=word
#pragma align=hword
#pragma align=dword

All of these are valid on at least one platform.  If one of these statements is compiled on a system that doesn't support that alignment the compiler generates an error.


This ends today's lesson on #pragma.  :)
Kdo
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now