What is use the of Pragma directives!!!

C

code break

Plz can any one tell methe actual use of Pragma directives in C &
googled for it but i'm not able to understand it clearly so can any
one tell me it's actual use in C..
 
E

Eric Sosman

code break wrote On 03/24/06 09:13,:
Plz can any one tell methe actual use of Pragma directives in C &
googled for it but i'm not able to understand it clearly so can any
one tell me it's actual use in C..

There is no Pragma directive in C. You are probably
thinking of the _Pragma directive.

_Pragma is a "standard way of being non-standard."
You use _Pragma to tell the compiler something that the
C language itself cannot express: things like "This
function never returns" or "This function has no side-
effects" or "Align this variable on a 8192-byte boundary."
The things that can be expressed and the exact way you
express them are implementation-defined, meaning that
they vary from one compiler to the next.

_Pragma (and #pragma, which does the same sort of
thing but with different syntax) has two effects on your
code. First and most obviously, it has the special effect
that the compiler documents for it. Second and more subtly,
it ties your code to that particular compiler, making it
exceedingly difficult to move your code to another -- you
will sometimes even find that you cannot upgrade to a
newer version of "the same" compiler without changing the
meaning of the _Pragma and #pragma directives in your code.

Because of the portability problems, _Pragma and
#pragma should be used only when there is no other practical
way to solve the problem at hand. But if you find yourself
in that situation, _Pragma and #pragma may be your only
recourse: necessity is a spur that is hard to ignore.
 
K

Keith Thompson

Eric Sosman said:
code break wrote On 03/24/06 09:13,:

There is no Pragma directive in C. You are probably
thinking of the _Pragma directive.

Actually, _Pragma is an operator (the usage is
_Pragma("string literal")), and #pragma is a directive.
_Pragma is a "standard way of being non-standard."
You use _Pragma to tell the compiler something that the
C language itself cannot express: things like "This
function never returns" or "This function has no side-
effects" or "Align this variable on a 8192-byte boundary."
The things that can be expressed and the exact way you
express them are implementation-defined, meaning that
they vary from one compiler to the next.

In C99, there are several language-defined #pragma directives:

#pragma STDC FP_CONTRACT on-off-switch
#pragma STDC FENV on-off-switch
#pragma STDC CX_LIMITED_RANGE on-off-switch

where on-off-switch is one of ON, OFF, or DEFAULT.

These are used to control some (fairly obscure) aspects of
floating-point computations. See the C99 standard (google
"n1124.pdf") for more details.

Future C standards may add more pragmas starting with STDC.
 
C

Chris Hulbert

Keith said:
Actually, _Pragma is an operator (the usage is
_Pragma("string literal")), and #pragma is a directive.


In C99, there are several language-defined #pragma directives:

#pragma STDC FP_CONTRACT on-off-switch
#pragma STDC FENV on-off-switch
#pragma STDC CX_LIMITED_RANGE on-off-switch

where on-off-switch is one of ON, OFF, or DEFAULT.

These are used to control some (fairly obscure) aspects of
floating-point computations. See the C99 standard (google
"n1124.pdf") for more details.

Future C standards may add more pragmas starting with STDC.

#pragma is also the way some standards such as openMP are implemented.
Compilers who can't understand the openMP pragmas can simply ignore it.
 
E

Eric Sosman

Chris Hulbert wrote On 03/24/06 14:53,:
#pragma is also the way some standards such as openMP are implemented.
Compilers who can't understand the openMP pragmas can simply ignore it.

There remains the danger that a compiler won't fail
to recognize a foreign #pragma and thus ignore it, but
will instead mis-understand it to mean something quite
different than was intended. For example,

#pragma align 8
struct guggle zatch;

.... quite likely specifies special alignment for `zatch'.
But is it asking for alignment on an eight-byte boundary
or on a 256-byte boundary? I've seen both conventions
used by actual compilers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top