Re: Standard PRAGMAs?



Joe Krahn <krahn@xxxxxxxxxxxxx> wrote:

compiler directives in common use are behind comment tags like !DEC$ and
are not standardized.

In some case, it is a bit stronger than "not standardized", for reasons
mentioned below.

One definition of pragma is "A standardized form of comment which has
meaning to a compiler."

I think you may have overlooked a subtlety here. In most of the
definitions I have seen, a fundamental point is that a PRAGMA does not
change the actual meaning of the code. That point is in your definition
above, but subtly so. In particular, that's why a pragma can validly be
described as a comment - comments don't change the meaning of the
program. The idea is supposed to be that if you compile the code on a
compiler that doesn't recognize the pragma, the code is still supposed
to be correct.

Now not all "pragmas" (I'm including the things like !DEC$ in the term)
strictly follow this ideal, but it is at least the ideal. When a pragma
strays from this ideal, it can result in code that actually violates the
standard when the praagma is ignored. That's what I was referring to
when I referred to being stronger than "not standardized".

enable/disable strict warnings or errors for the selected standard.

Things along that general line are common cases of proposed pragmas.
Some debugging aids are similar.

One variant is something comparable to an assert. You could consider
that to be a pragma in a way in that an assert should not have any
effect on the meaning of the code if all is well.

adjust compiler optimizations (only general settings)

That's a common one, but...

Options should generally be limited to a whole source file to make it
possible to implement them outside of the actual compiler.

Pragmas used for optimization hints are often far more specific. Namely,
they sometimes give hints about how best to optimize thnigs like
individual DO loops. HPF is a *MAJOR* example of this. Most of HPF can
be considered as optimization hints in some sense; the code will run if
the compiler ignore them all, but it might run a whole lot faster if the
compiler understands and implements them. (Or anyway, that's the
theory).

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
.



Relevant Pages

  • Re: classes, strings, learning in VS.NET
    ... >> guards in header files, even when leaving those out would not cause ... Since we are discussing standard C++ here, I prefer to stay as close to ... compiler should do when it encounters #pragma once, ... it in case the compiler does not recognize it. ...
    (comp.lang.cpp)
  • Re: Wie = überladen für Zeigerzuweisung?
    ... > Was sollte ein anderer Compiler beim Strukturaufbau anders machen? ... Die Reihenfolge ist so festgelegt, ... Das #pragma pack() ist auch nicht standardisiert. ... Im Standard steht nur, dass "#pragma" als Precompiler-Direktive ...
    (microsoft.public.de.vc)
  • Re: fixed point math library?
    ... in cases like this and changing that would change the meaning of the ... As long as a compiler produces the same results as the standard ... with close attention to the needs of folks working on 8-bit CPUs. ...
    (comp.arch.embedded)
  • Standard PRAGMAs?
    ... the only compiler directives in common use are behind comment tags like!DEC$ and are not standardized. ... Many of these are to detailed for a general-purpose standard, and many will be obsolete with F2003. ... My suggestion for a common Fortran pragma is simply a comment starting with PRAGMA, followed by a list of properties formatted similar to Fortran attributes, either simple tokens or parenthesized arguments: ... Options should generally be limited to a whole source file to make it possible to implement them outside of the actual compiler. ...
    (comp.lang.fortran)
  • Re: Linux X demo
    ... I know, but the question was, why doesn't the compiler emit an ... defined meaning on all such constructs would go against the ethos of ... processed without an error message. ... The standard can't insist the compiler do something ...
    (comp.lang.c)