• C

#pragma usage

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

Thanks,
Arut
arutAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
ON-DEMAND: 10 Easy Ways to Lose a Password

Learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees in this on-demand webinar. We cover the importance of multi-factor authentication and how these solutions can better protect your business!

bharat_maneCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.