Topic: pragmas (was: \e (was: Why's of C++ -- Part 3 ...))
Author: fjh@cs.mu.OZ.AU (Fergus Henderson)
Date: 1999/10/04 Raw View
Russell Bornschlegel <kaleja@rahul.net> writes:
>Pete Becker wrote:
>>
>> Some folks think that #pragma should not be in the standard. Was it GNU
>> C that used to start a game of nethack when it encountered a #pragma?
...
>Objecting to #pragma on theoretical/theological grounds while supporting
>"computed goto", nested functions, "x?:y", and the like seems, at best,
>inconsistent, doesn't it?
The GNU C manual's description of the GNU C `__attribute__' extension
contains two arguments against `#pragma':
| Some people object to the `__attribute__' feature, suggesting that
| ANSI C's `#pragma' should be used instead. There are two reasons for
| not doing this.
|
| 1. It is impossible to generate `#pragma' commands from a macro.
|
| 2. There is no telling what the same `#pragma' might mean in another
| compiler.
|
| These two reasons apply to almost any application that might be
| proposed for `#pragma'. It is basically a mistake to use `#pragma' for
| *anything*.
The first of these two arguments is fixed in C9X, which introduces
`_Pragma' as a form of `#pragma' that can be used in macros.
The second of these two arguments is basically bogus now too, since
the argument applies just as well to `__attribute__' as it does to
`_Pragma'. In practice, the way these are used in portable code is
in macros protected by conditional compilation:
#ifdef __GNUC__
#define NO_RETURN __attribute__((__no_return__))
#else
#define NO_RETURN
#endif
So solving the problem of #pragmas not being allowed in macros
has also solved the problem of pragmas meaning different things
in different compilers.
Another alternative solution to the second problem is for each compiler
to adopt a prefix (e.g. `GNUC') for their pragmas. But if uses of
pragmas are always protected by conditional compilation, then this
isn't essential.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]