S
Shri
Can anybody tell me where i can find a detailed document on #pragma ....
--shri
--shri
Can anybody tell me where i can find a detailed document on #pragma ....
Shri said:Can anybody tell me where i can find a detailed document on #pragma ....
--shri
In said: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:
[ The "#pragma once" directive is employed as a guard for header
files. Its main purpose is to avoid multiple inclusions.
This [is] equivalent to:
#ifdef __HEADER_FILE__
#define __HEADER_FILE__
/* some declarations go here ... */
#endif /* __HEADER_FILE__ */
Arthur J. O'Dwyer said: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]
[ 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:
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
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.