Title : About pragma
Author: Peter Van Der Linden,<Expert C Programming Deep C Secrets>
Some Light Relief—The Implementation-Defined Effects of Pragmas . . .
The Free Software Foundation is a unique organization founded by ace MIT hacker Richard Stallman.By the way, we use “hacker” in the old benevolent sense of “gifted programmer;” the term has been debased by the media, so outsiders use it to mean “evil genius.” Like the adjective bad, “hacker” now has two opposing meanings, and you have to figure it out from the context.
Stallman’s Free Software Foundation was founded on the philosophy that software should be free and freely available to all. FSF’s charter is “to eliminate restrictions on copying, redistribution, understanding and modification of computer programs” and their ambition is to create a publicdomain implementation of UNIX called GNU (it stands for “GNU’s Not UNIX.” Yes, really.)
Many computer science graduate students and others agree with the GNU philosophy, and have worked on software products that FSF packages and distributes for free. This pool of skilled labor donating their talent has resulted in some good software. One of FSF’s best products is the GNU C compiler family. gcc is a robust, aggressive optimizing compiler, available for many hardware platforms and sometimes better than the manufacturer’s compiler. Using gcc would not be appropriate for all projects; there are questions of maintenance and future product continuity. There are other tools needed besides a compiler, and the GNU debugger was unable to operate on shared libraries for a long time. GNU C has also occasionally been a little, shall we say, giddy in development.
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 in-line or suppress range checks. Not previously seen in C, pragma met with some initial resistance from a gcc implementor, who took the “implementation-defined” effect very literally—in gcc version 1.34, the use of pragma causes the compiler to stop compiling and launch a
computer game instead! The gcc manual contained the following:
The “#pragma” command is specified in the ANSI standard to have an arbitrary implementationdefined effect. In the 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 the Tower of Hanoi; if that fails, it reports a fatal error. In any case, preprocessing does not continue.
—Manual for version 1.34 of the GNU C compiler
And the corresponding source code in the preprocessor part of the compiler was:
/*
* the behavior of the #pragma directive is implementation defined.
* this implementation defines it as follows.
*/
do_pragma ()
{
close (0);
if ( open( “/dev/tty”, O_RDONLY, 0666 ) != 0 )
goto nope;
close (1);
if ( open( “/dev/tty”, O_WRONLY, 0666 ) != 1 )
goto nope;
execl( “/usr/games/hack”, “#pragma”, 0 );
execl( “/usr/games/rogue”, “#pragma”, 0 );
execl( “/usr/new/emacs”, “-f”, “hanoi”, “9″, “-kill”, 0 );
execl( “/usr/local/emacs”, “-f”, “hanoi”, “9″, “-kill”, 0 );
nope:
fatal( “You are in a maze of twisty compiler features, all different” );
}
Especially droll is the fact that the description in the user manual is wrong, in that the code shows that “hack” is tried before “rogue”.
-
近期文章
近期评论
- coolker 发表在《打造最快的Hash表》
- struggle 发表在《提供C语言教学课件(适用于初学者)》
- zhanghaibo 发表在《提供C语言教学课件(适用于初学者)》
- zhanghaibo 发表在《提供C语言教学课件(适用于初学者)》
- diys 发表在《C语言编程宝典(王大刚) 1.1 C 语言的产生与发展》
文章归档
- 2022 年十月
- 2014 年一月
- 2013 年十二月
- 2012 年十一月
- 2012 年七月
- 2012 年六月
- 2012 年五月
- 2012 年四月
- 2012 年三月
- 2012 年二月
- 2011 年十二月
- 2011 年十月
- 2011 年九月
- 2011 年八月
- 2011 年七月
- 2011 年六月
- 2011 年五月
- 2011 年四月
- 2011 年三月
- 2011 年二月
- 2011 年一月
- 2010 年十二月
- 2010 年十一月
- 2010 年十月
- 2010 年九月
- 2010 年八月
- 2010 年七月
- 2010 年六月
- 2010 年五月
- 2010 年四月
- 2010 年三月
- 2010 年二月
- 2010 年一月
- 2009 年十二月
- 2009 年十一月
- 2009 年十月
- 2009 年九月
- 2009 年八月
- 2009 年七月
- 2009 年六月
- 2009 年五月
- 2009 年四月
- 2009 年三月
- 2009 年二月
- 2009 年一月
- 2008 年十二月
- 2008 年十一月
- 2008 年十月
- 2008 年九月
- 2008 年八月
- 2008 年七月
- 2008 年六月
- 2008 年五月
- 2008 年四月
- 2008 年三月
- 2008 年二月
- 2008 年一月
- 2007 年十二月
- 2007 年十一月
- 2007 年十月
- 2007 年九月
- 2007 年八月
- 2007 年七月
- 2007 年六月
- 2007 年三月
- 2007 年二月
- 2007 年一月
- 2006 年十二月
- 2006 年十一月
- 2006 年十月
- 2006 年九月
- 2006 年八月
- 2006 年七月
- 2006 年六月
- 2006 年五月
- 2006 年四月
- 2006 年三月
- 2006 年二月
- 2006 年一月
- 2005 年十二月
- 2005 年十一月
分类目录
功能