Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!hplabs!hpda!hpcuhb!hpcllla!hpclisp!hprsue!sue From: sue@hprsue.HP.COM (Sue Meloy) Newsgroups: comp.std.c Subject: Re: Re: #pragma Message-ID: <12570056@hprsue.HP.COM> Date: 30 Nov 90 00:07:51 GMT References: <9011272328.AA03163@decpa.pa.dec.com> Organization: Hewlett-Packard Calif. Language Lab Lines: 62 Norman Diamond writes: > Not at all. A program which wants to be conforming and executable on all > implementations, but obtain some feature from an implementation which > recognizes a particular #pragma, should use #pragma. A program which > DEPENDS on a non-portable construction should use an extended #directive > and/or __identifier that is offered by the particular implementation. > > This is exactly why the standard says that if an implementation does not > recognize a particular #pragma, it should ignore it. If an implementation > does not recognize a #funny_directive or __reserved_identifier, it is > supposed to issue a diagnostic. Implementation-dependent programs that > are coded in Mr. Unni's style will not receive the desired diagnostics > from other implementations. > > The instructions that an unrecognized #pragma be ignored are now either > useless or, worse, counterproductive. Unfortunately, the ANSI committee > seems to have forgotten their own wishes. There are still pitfalls even with #pragma. Just because an implementation "recognizes" the pragma does not mean that it will do what the programmer intends. One implementation may interpret #pragma list to mean that a program listing should be generated, while another could interpret this to mean that this month's accounts payable transactions should be dumped to the line printer. The only safe thing is for all implementation-specific directives to be protected by ifdefs. Thus, a conforming program can contain pragmas which could affect the behavior of a strictly conforming program, but can continue to be compiled on an implementation that does not make use of those pragmas. For example (no noalias diatribes, please!), do_something(int *vector1, int *vector2) #ifdef WHIZBANG_C #pragma noalias vector1,vector2 #endif { /* do some stuff that could be vectorized if vector1 and vector2 * are not aliased to one another. */ } If WHIZBANG_C is not defined, this code must be accepted and run as specified by the standard on all conforming implementations. Whether it does the right thing on WHIZBANG_C is a quality-of-implementation/ quality-of-programmer issue. This brings up another question: If a non-standard directive name is used instead, is a conforming implementation required to accept it if it appears inside a skipped section of code? The standard does not appear to be completely clear on this point; it says that in this case "... directives are processed only through the name that determines the directive in order to keep track of the level of nested conditionals...". My gut feel is that even this limited amount of processing would require a diagnostic if the directive name is not standard. Sue Meloy sue@hpcllca.cup.hp.com