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__ */
But, #pragma is not a portable mean of avoiding multiple
inclusions. The ANSI C standard declares it as
implementation-defined. There is one small story, which
I came across while reading a book:
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."