Thuis Hobby Werk spam Code WWW
spbox icon Geo caching hacker ASCII

#pragma in gcc

 

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."

Here's an excerpt from the gcc source, version 1.35, released in 1989 (note the "#if 0"):

#if 0
/* This was a fun hack, but #pragma seems to start to be useful.
   By failing to recognize it, we pass it through unchanged to cc1. */

/*
 * 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");
}
#endif

Share and Enjoy: del.icio.us Reddit digg Furl Spurl NewsVine Smarking Ma.gnolia Wists Simpy TailRank co.mments YahooMyWeb blinkbits BlinkList blogmarks connotea De.lirio.us Fark feedmelinks LinkaGoGo Netvouz RawSugar scuttle Shadows

spbox icon Geo caching hacker ASCII
Thuis Hobby Werk spam Code WWW

Toni Cornelissen
1 januari 1970
toni@dse.nl
Lid van de Technetium groep
Daily horoscope StatCounter NetStat W3C Validator