By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,852 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,852 IT Pros & Developers. It's quick & easy.

Pragma Document

P: n/a
Can anybody tell me where i can find a detailed document on #pragma ....

--shri
Nov 14 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
sh*********@yahoo.com (Shri) writes:
Can anybody tell me where i can find a detailed document on #pragma ....


There aren't many details to tell. #pragma is (in C90) entirely
or (in C99) mostly implementation-dependent. If you want to know
how your compiler interprets #pragma, refer to its documentation.
--
"Your correction is 100% correct and 0% helpful. Well done!"
--Richard Heathfield
Nov 14 '05 #2

P: n/a

"Shri" <sh*********@yahoo.com> wrote in message news:8a**************************@posting.google.c om...
Can anybody tell me where i can find a detailed document on #pragma ....

--shri


The ANSI C standard declares #pragma as implementation-defined.
There is one small story, which I came across while reading the book,
Deep C Secrets:

When the ANSI C standard was under development, the
pragma directive was introduced. Borrowed from Ada, #pragma
is used to convey hints to the compiler, such as the desire
to expand a particular function as in-line or suppress some
range checks. #pragma met with some initial resistancee from
a gcc implementor, who took the "implementation-defined" effect
very literally. In gcc version 1.34, the use of pragma caused
the compiler to stop compiling and launch a computer game instead.
The gcc version 1.34 manual said:

"The #pragma command is specified in the ANSI standard to have
an arbitrary implementation-defined effect. In GNU C preprocessor,
#pragma first attempts to run the game "rogue"; if that fails,
it tries to run the game "hack"; if that fails, it tries to run
GNU Emacs displaying Tower Of Hanoi; if that fails, it reports
a fatal error. In any case, preprocessing does not continue."

[ The "#pragma once" directive is employed as a guard for header
files. Its main purpose is to avoid multiple inclusions.
This equivalent to:

#ifdef __HEADER_FILE__
#define __HEADER_FILE__

/* some declarations go here ... */

#endif /* __HEADER_FILE__ */ ]

--
Vijay Kumar R Zanvar
My Home Page - http://www.geocities.com/vijoeyz/
Nov 14 '05 #3

P: n/a
since #pragma is a command to the compiler it is compiler specific.
Therefore it will vary by compiler or compiler version.

Shri wrote:
Can anybody tell me where i can find a detailed document on #pragma ....

--shri


Nov 14 '05 #4

P: n/a
In 'comp.lang.c', sh*********@yahoo.com (Shri) wrote:
Can anybody tell me where i can find a detailed document on #pragma ....


On you compilers documentation only.

(Don't use #pragma to stay portable)

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #5

P: n/a

On Mon, 31 May 2004, Vijay Kumar R Zanvar wrote:

"Shri" <sh*********@yahoo.com> wrote
Can anybody tell me where i can find a detailed document on #pragma ....
The ANSI C standard declares #pragma as implementation-defined.
There is one small story, which I came across while reading the book,
Deep C Secrets:


[by Peter van der Linden, BTW]
<snip anecdote>
[ The "#pragma once" directive is employed as a guard for header
files. Its main purpose is to avoid multiple inclusions.
It is not standard, and IMHO probably never will be, due to the
difficulty of specifying exactly what it is that '#pragma once' is
supposed to do. (Consider two identical copies of a header file
in different source directories, and a TU that #includes both of
them. What is the effect of '#pragma once' here? Make sure to
give it implementation-independent and well-defined semantics. :)
This [is] equivalent to:

#ifdef __HEADER_FILE__
#define __HEADER_FILE__

/* some declarations go here ... */

#endif /* __HEADER_FILE__ */


Except that no extra macro-names are introduced into either the
header file itself *or* the translation unit with the '#include'
directive in it, and of course the sense of the implicit "comparison"
is reversed from what Vijay has written.
The Standard C method of "header guards" looks like this. Note
particularly the '#ifndef' and the name 'H_FOO', which is guaranteed
to be in the user's namespace and not the implementation's (unlike
'__HEADER_FILE__', which makes Vijay's example non-conforming).

#ifndef H_FOO /* for a file "foo.h" */
#define H_FOO

/* header contents: type definitions and extern declarations */

#endif

There is also some C++ magic that usually gets wrapped around
that, in case the library gets used in a C++ program, but I can
never remember all the details of it. Check Google.

-Arthur
Nov 14 '05 #6

P: n/a

"Arthur J. O'Dwyer" <aj*@nospam.andrew.cmu.edu> wrote in message news:Pi**********************************@unix49.a ndrew.cmu.edu...

On Mon, 31 May 2004, Vijay Kumar R Zanvar wrote:

"Shri" <sh*********@yahoo.com> wrote
Can anybody tell me where i can find a detailed document on #pragma ....


The ANSI C standard declares #pragma as implementation-defined.
There is one small story, which I came across while reading the book,
Deep C Secrets:


[by Peter van der Linden, BTW]
<snip anecdote>
[ The "#pragma once" directive is employed as a guard for header
files. Its main purpose is to avoid multiple inclusions.


It is not standard, and IMHO probably never will be, due to the
difficulty of specifying exactly what it is that '#pragma once' is
supposed to do. (Consider two identical copies of a header file
in different source directories, and a TU that #includes both of
them. What is the effect of '#pragma once' here? Make sure to
give it implementation-independent and well-defined semantics. :)
This [is] equivalent to:

Yes. It *ees*.
#ifdef __HEADER_FILE__
#define __HEADER_FILE__

/* some declarations go here ... */

#endif /* __HEADER_FILE__ */


Except that no extra macro-names are introduced into either the
header file itself *or* the translation unit with the '#include'
directive in it, and of course the sense of the implicit "comparison"
is reversed from what Vijay has written.
The Standard C method of "header guards" looks like this. Note
particularly the '#ifndef' and the name 'H_FOO', which is guaranteed
to be in the user's namespace and not the implementation's (unlike
'__HEADER_FILE__', which makes Vijay's example non-conforming).

#ifndef H_FOO /* for a file "foo.h" */
#define H_FOO

/* header contents: type definitions and extern declarations */

#endif

There is also some C++ magic that usually gets wrapped around
that, in case the library gets used in a C++ program, but I can
never remember all the details of it. Check Google.

-Arthur


Thank you sir for pointing out my mistakes.

Vijay
Nov 14 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.