Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!pyramid!decwrl!thundr.dec.com!minow From: minow@thundr.dec.com (Martin Minow THUNDR::MINOW ML3-5/U26 223-9922) Newsgroups: comp.lang.c Subject: re: Pragmas Message-ID: <8801021358.AA15890@decwrl.dec.com> Date: 2 Jan 88 16:50:00 GMT Organization: Digital Equipment Corporation Lines: 47 bbn!kgregory asks for examples of #pragma usage. Here are a few: -- Decus C has compiler-specific keywords to determine storage allocation (program sections) -- this let you write data into specific areas that were resolved to absolute base addresses by the linker. This is essential if you are writing a program that will subsequently be run from ROM; you must force code and tables into read-only memory and non-static data into ram. This also let us develop a facility that called specific functions at the start and/or end of execution. The function registry mechanism used program sections to manage a table of routines to call: all of the mechanism was done by the compiler. The Draft Standard has an "atexit()" registry that is managed by explicit calls by the running program. Decus C has both "atexit" and "atentrance" which are triggered by the inclusion of the module, and require no programmer intervention. -- On some architectures, such as the Vax, certain instructions may not be used to access device registers. A statement such as #pragma device_register foo, bar; might be useful to prevent certain optimizations. Note that the architectural restriction goes beyond what "volatile" can accomplish. -- On architectures such as the 80x86 family, one can achieve useful optimization by adding "near" and "far" pragmas. -- One might use #pragma's to enable/disable debugging or self-testing code. While all of the above can be achieved by using implementation-specific keywords (beginning with _), #pragma is a useful addition to the language. According to the Draft Standard, unknown pragmas are to be ignored (section 3.8.6 of the Aug. '87 draft). Because it doesn't distinguish mistakes from typographical errors, this is a mistake, and one that the Committee seems inordinately fond of: they rejected my request to flag unknown pragmas as errors. The Gnu compiler "recognizes" all pragmas, causing them to run Towers of Hanoi to a depth of 64. This is proper usage per the Draft Standard. Martin Minow minow%thundr.dec@decwrl.dec.com decvax!decwrl!dec-rhea!dec-thundr!minow ======================================================================== Received: by decwrl.dec.com (5.54.4/4.7.34) id AA06740; Fri, 1 Jan 88 19:31:42 PST