When to emit diagnistics

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jacob navia

    When to emit diagnistics

    Recently we had a discussion about the following code:

    void f(long *lp) { *lp = 0; }
    int main(void) { int i; f(&i); return i; }

    lcc-win doesn't emit any diagnostic in normal mode, and doesn't
    emit a diagnostic with the higher warning level.

    It emits a diagnostic only in the highest warning level:

    lcc -A -A foo.c

    will diagnostic that with a warning.

    Why?

    Because under windows (32 and 64 bits) there is
    absolutely no PRACTICAL difference between a
    long and an int. They are completely equivalent types.

    The diagnostic would just add CLUTTER and NOISE to
    the output of the compiler.

    The problem is that if the compiler emits too many diagnostics
    the important ones will go unnoticed, swallowed by the noise
    of the unimportant ones.

    Note that Microsoft C, for instance will not diagnose this
    even with the highest warning level.

    This are the reasons behind the decision. Some people like
    heathfield or becarisse use this as a "proof that lcc-win is
    useless", etc. Their usual stuff. Note that lcc-win is not
    just for pleasing pedants in comp.lang.c but it is useful
    for doing REAL work. The objective is not to please
    pedants here.


    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique

  • Joachim Schmitz

    #2
    Re: When to emit diagnistics

    jacob navia wrote:
    Recently we had a discussion about the following code:
    >
    void f(long *lp) { *lp = 0; }
    int main(void) { int i; f(&i); return i; }
    >
    lcc-win doesn't emit any diagnostic in normal mode, and doesn't
    emit a diagnostic with the higher warning level.
    >
    It emits a diagnostic only in the highest warning level:
    >
    lcc -A -A foo.c
    >
    will diagnostic that with a warning.
    Good. One problem solved. Now document that switch in your manual.
    Why?
    >
    Because under windows (32 and 64 bits) there is
    absolutely no PRACTICAL difference between a
    long and an int. They are completely equivalent types.
    >
    The diagnostic would just add CLUTTER and NOISE to
    the output of the compiler.
    >
    The problem is that if the compiler emits too many diagnostics
    the important ones will go unnoticed, swallowed by the noise
    of the unimportant ones.
    All valid points, indeed.
    Note that Microsoft C, for instance will not diagnose this
    even with the highest warning level.
    Haven't tested this myself, but a far as I understood others (namely RH), it
    it does diagnose this if called _in conforming mode_. So please don't
    continue comparing apples with peaches.
    This are the reasons behind the decision. Some people like
    heathfield or becarisse use this as a "proof that lcc-win is
    useless", etc. Their usual stuff. Note that lcc-win is not
    just for pleasing pedants in comp.lang.c but it is useful
    for doing REAL work. The objective is not to please
    pedants here.
    Nobody claimed win-lcc to be useless. The only claim here (and plenty proof
    for it) was that win-lcc does not (unlike your claim) conform to either
    C89/C90 or C99.
    So it is a compiler for a C-like language, no more, no less. That doesn't
    make it useless.

    Bye, Jojo


    Comment

    • santosh

      #3
      Re: When to emit diagnistics

      jacob navia wrote:
      Recently we had a discussion about the following code:
      >
      void f(long *lp) { *lp = 0; }
      int main(void) { int i; f(&i); return i; }
      >
      lcc-win doesn't emit any diagnostic in normal mode, and doesn't
      emit a diagnostic with the higher warning level.
      >
      It emits a diagnostic only in the highest warning level:
      >
      lcc -A -A foo.c
      The problem is you have not (as far as I can tell) *documented* this
      switch combination. Undocumented features are IMO worse than
      unimplemented features.
      will diagnostic that with a warning.
      >
      Why?
      >
      Because under windows (32 and 64 bits) there is
      absolutely no PRACTICAL difference between a
      long and an int. They are completely equivalent types.
      You are assuming here that any Standard C program compiled with lcc-win
      under Windows has no chance of later being ported to a different
      system.

      This warning is absolutely essential for a user who considers
      portability to be important.
      The diagnostic would just add CLUTTER and NOISE to
      the output of the compiler.
      Then why not add a specific switch for enabling warnings of this class,
      like say gcc? Or you could arrange for the '-A' switch to take a
      numeric value which would specify the warning level. Necessitating
      *two* instances of the '-A' switch is very counter-intuitive.

      Don't be afraid to add more command line switches. A C compiler is a
      serious tool, and a professional programmer is expected to study it
      thoroughly as a part of his job.
      The problem is that if the compiler emits too many diagnostics
      the important ones will go unnoticed, swallowed by the noise
      of the unimportant ones.
      That's what different diagnostic levels are for. If a programmer
      explicitly asks for *all* possible diagnostics, then he is presumably
      prepared to deal with some innocuous ones.
      Note that Microsoft C, for instance will not diagnose this
      even with the highest warning level.
      >
      This are the reasons behind the decision. Some people like
      heathfield or becarisse use this as a "proof that lcc-win is
      useless", etc. Their usual stuff. Note that lcc-win is not
      just for pleasing pedants in comp.lang.c but it is useful
      for doing REAL work. The objective is not to please
      pedants here.
      No one said lcc-win was "useless" or just for "pleasing pedants". This
      thread developed because you claimed that lcc-win conforms to both C90
      and C99 which is clearly not the case.

      Regardless of conformance, one of the real advantages of HLLs is the
      rigorous automated checking that is possible. People are prone to
      errors and typos. A tool that catches them (even at the risk of some
      false positives) is superior to one that has reduced ability in this
      regard.

      IME Intel's compiler has somewhat better diagnostics than even gcc. You
      would do well to study it's behaviour and strive to emulate it. IMO of
      course.

      Comment

      • Richard Heathfield

        #4
        Re: When to emit diagnistics

        jacob navia said:
        Recently we had a discussion about the following code:
        >
        void f(long *lp) { *lp = 0; }
        int main(void) { int i; f(&i); return i; }
        >
        lcc-win doesn't emit any diagnostic in normal mode, and doesn't
        emit a diagnostic with the higher warning level.
        >
        It emits a diagnostic only in the highest warning level:
        >
        lcc -A -A foo.c
        >
        will diagnostic that with a warning.
        A diagnostic message is required for constraint violations and syntax
        errors. If your implementation doesn't issue one, it doesn't conform to
        the language spec.
        Why?
        >
        Because under windows (32 and 64 bits) there is
        absolutely no PRACTICAL difference between a
        long and an int. They are completely equivalent types.
        >
        The diagnostic would just add CLUTTER and NOISE to
        the output of the compiler.
        >
        The problem is that if the compiler emits too many diagnostics
        the important ones will go unnoticed, swallowed by the noise
        of the unimportant ones.
        Syntax errors and constraint violations are pretty important.
        >
        Note that Microsoft C, for instance will not diagnose this
        even with the highest warning level.
        Liar. When you first claimed this, it was reasonable to assume you were
        mistaken. But after you claimed it three times, I checked it and told you
        "MSVC diagnoses this error properly when invoked in conforming mode", and
        you replied "and lcc-win also", in an article timestamped 12 minutes or so
        before your "When to emit diagnistics" article. So you knew and accepted
        that Microsoft C does indeed diagnose this error, which makes you a liar
        for pretending that it doesn't.
        This are the reasons behind the decision. Some people like
        heathfield or becarisse use this as a "proof that lcc-win is
        useless", etc.
        Liar. I have never claimed that lcc-win is useless. I *have* claimed that
        it isn't a C compiler, and you seem to agree, since you don't appear to
        claim either C90 or C99 conformance for it.
        Their usual stuff. Note that lcc-win is not
        just for pleasing pedants in comp.lang.c but it is useful
        for doing REAL work. The objective is not to please
        pedants here.
        If you want to get real work done, use a compiler that implements the
        language it claims to implement.

        --
        Richard Heathfield <http://www.cpax.org.uk >
        Email: -http://www. +rjh@
        Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
        "Usenet is a strange place" - dmr 29 July 1999

        Comment

        • Ian Collins

          #5
          Re: When to emit diagnistics

          jacob navia wrote:
          Recently we had a discussion about the following code:
          >
          void f(long *lp) { *lp = 0; }
          int main(void) { int i; f(&i); return i; }
          >
          lcc-win doesn't emit any diagnostic in normal mode, and doesn't
          emit a diagnostic with the higher warning level.
          >
          It emits a diagnostic only in the highest warning level:
          >
          lcc -A -A foo.c
          >
          will diagnostic that with a warning.
          >
          Why?
          >
          Because under windows (32 and 64 bits) there is
          absolutely no PRACTICAL difference between a
          long and an int. They are completely equivalent types.
          >
          But they are incompatible types. I thought you'd made a Linux port of
          the compiler? There you would have an issue.

          Both Sun cc and gcc warn on their default settings.
          The diagnostic would just add CLUTTER and NOISE to
          the output of the compiler.
          >
          The problem is that if the compiler emits too many diagnostics
          the important ones will go unnoticed, swallowed by the noise
          of the unimportant ones.
          >
          Most shops have a "no warnings in the build" rule for that very reason.
          It isn't hard to do.

          --
          Ian Collins.

          Comment

          • Richard Heathfield

            #6
            Re: When to emit diagnistics

            Ian Collins said:

            <snip>
            Most shops have a "no warnings in the build" rule for that very reason.
            It isn't hard to do.
            Not if you only have to cater for one compiler, no. There's usually a way
            of shutting most compilers up, for any given spurious warning.
            Unfortunately, the way to shut one compiler up might well trigger a
            warning under a different compiler. Compiling the same source base cleanly
            under multiple implementations is not a trivial exercise.

            --
            Richard Heathfield <http://www.cpax.org.uk >
            Email: -http://www. +rjh@
            Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
            "Usenet is a strange place" - dmr 29 July 1999

            Comment

            • Ian Collins

              #7
              Re: When to emit diagnistics

              Richard Heathfield wrote:
              Ian Collins said:
              >
              <snip>
              >
              >Most shops have a "no warnings in the build" rule for that very reason.
              > It isn't hard to do.
              >
              Not if you only have to cater for one compiler, no. There's usually a way
              of shutting most compilers up, for any given spurious warning.
              Unfortunately, the way to shut one compiler up might well trigger a
              warning under a different compiler. Compiling the same source base cleanly
              under multiple implementations is not a trivial exercise.
              >
              In that case use minimum warning levels and lint.

              --
              Ian Collins.

              Comment

              • santosh

                #8
                Re: When to emit diagnistics

                Keith Thompson wrote:
                jacob navia <jacob@nospam.c omwrites:
                >Recently we had a discussion about the following code:
                >>
                >void f(long *lp) { *lp = 0; }
                > int main(void) { int i; f(&i); return i; }
                >
                Which clearly violates a constraint.
                >
                >lcc-win doesn't emit any diagnostic in normal mode, and doesn't
                >emit a diagnostic with the higher warning level.
                >
                Out of curiosity, does lcc-win emit a diagnostic for this?
                >
                int main(void)
                {
                long obj = 42;
                int *ptr = &obj;
                return 0;
                }
                >
                What about the equivalent using an assignment rather than an
                initialization?
                It does (at least my copy of it). In both cases the diagnostic is:

                Warning test.c: 5 assignment of pointer to long int to pointer to int

                In addition:

                Warning test.c: 4 ptr is assigned a value that is never used

                is also emitted.

                <snip>

                Comment

                • Spiro Trikaliotis

                  #9
                  Re: When to emit diagnistics

                  Hello,

                  jacob navia wrote:
                  Recently we had a discussion about the following code:
                  >
                  void f(long *lp) { *lp = 0; }
                  int main(void) { int i; f(&i); return i; }
                  [...]
                  Note that Microsoft C, for instance will not diagnose this
                  even with the highest warning level.
                  This is not true. I just tried it with Visual C++ 6.0, all service packs
                  applied:

                  default settings: (warning level 3): No warning
                  incremented warning level to 4: No warning

                  warning level back to 3, but "disable language extensions" active:

                  C:\test\a.c(9) : warning C4133: 'function' : incompatible types - from 'int *' to 'long *'

                  This is exactly what I have expected.

                  I do not expect a compiler must emit the warning if it does not claim to
                  be conforming ("language extensions") - although, I would love it.
                  However, I expect it to emit these warnings if in compliant mode - and
                  MSVC6 does.

                  Note that this is MSVC6, which is ten years old.

                  Regards,
                  Spiro.

                  "Anybody who would spend considerable effort emulating a C64 is not
                  particularly sane to begin with; it is unreasonable to expect them to produce
                  sane software."
                  ("asuffield" in http://forums.thedailywtf.com/forums/p/7199/134136.aspx)

                  --
                  Spiro R. Trikaliotis http://opencbm.sf.net/
                  http://www.trikaliotis.net/ http://www.viceteam.org/

                  Comment

                  • Joachim Schmitz

                    #10
                    Re: When to emit diagnistics

                    Spiro Trikaliotis wrote:
                    Hello,
                    >
                    jacob navia wrote:
                    >
                    >Recently we had a discussion about the following code:
                    >>
                    >void f(long *lp) { *lp = 0; }
                    > int main(void) { int i; f(&i); return i; }
                    >
                    [...]
                    >
                    >Note that Microsoft C, for instance will not diagnose this
                    >even with the highest warning level.
                    >
                    This is not true. I just tried it with Visual C++ 6.0, all service
                    packs
                    applied:
                    >
                    default settings: (warning level 3): No warning
                    incremented warning level to 4: No warning
                    >
                    warning level back to 3, but "disable language extensions" active:
                    >
                    C:\test\a.c(9) : warning C4133: 'function' : incompatible types -
                    from 'int *' to 'long *'
                    >
                    This is exactly what I have expected.
                    And the considerably younger VC 8.0, AKA Visual Studio 2005, is giving
                    exatly the same warning, down to warning level 1, as long as language
                    extension are disabled (i.e. working in conforming mode).

                    Bye, Jojo


                    Comment

                    • jacob navia

                      #11
                      Re: When to emit diagnistics

                      Joachim Schmitz wrote:
                      Spiro Trikaliotis wrote:
                      >Hello,
                      >>
                      >jacob navia wrote:
                      >>
                      >>Recently we had a discussion about the following code:
                      >>>
                      >>void f(long *lp) { *lp = 0; }
                      >> int main(void) { int i; f(&i); return i; }
                      >[...]
                      >>
                      >>Note that Microsoft C, for instance will not diagnose this
                      >>even with the highest warning level.
                      >This is not true. I just tried it with Visual C++ 6.0, all service
                      >packs
                      >applied:
                      >>
                      >default settings: (warning level 3): No warning
                      >incremented warning level to 4: No warning
                      >>
                      >warning level back to 3, but "disable language extensions" active:
                      >>
                      >C:\test\a.c( 9) : warning C4133: 'function' : incompatible types -
                      >from 'int *' to 'long *'
                      >>
                      >This is exactly what I have expected.
                      And the considerably younger VC 8.0, AKA Visual Studio 2005, is giving
                      exatly the same warning, down to warning level 1, as long as language
                      extension are disabled (i.e. working in conforming mode).
                      >
                      Bye, Jojo
                      >
                      >
                      I did not know that you have to disable language extensions
                      to get a warning.

                      Anyway, that obscure option matches lcc -A -A obscure option.


                      --
                      jacob navia
                      jacob at jacob point remcomp point fr
                      logiciels/informatique

                      Comment

                      • Eric Sosman

                        #12
                        Re: When to emit diagnistics

                        jacob navia wrote:
                        Recently we had a discussion about the following code:
                        >
                        void f(long *lp) { *lp = 0; }
                        int main(void) { int i; f(&i); return i; }
                        >
                        lcc-win doesn't emit any diagnostic in normal mode, and doesn't
                        emit a diagnostic with the higher warning level.
                        >
                        It emits a diagnostic only in the highest warning level:
                        >
                        lcc -A -A foo.c
                        >
                        will diagnostic that with a warning.
                        Since the diagnostic is required, it follows that using the
                        highest warning level is a prerequisite for operating the compiler
                        in a conforming mode.
                        Why?
                        >
                        Because under windows (32 and 64 bits) there is
                        absolutely no PRACTICAL difference between a
                        long and an int. They are completely equivalent types.
                        They are distinct types that happen (on this implementation)
                        to share the same underlying representation.

                        This is a difficult notion for assembly programmers to grasp:
                        They tend to think about "type" in the way the hardware does, so
                        the idea of distinct types with identical behavior seems to them
                        obfuscatory. Angels on pinheads, academic piffle, and so on.

                        But the distinction is real, and also useful. Let me pose
                        a rhetorical question: If int and long are really the same, why
                        do programmers write `int' at some places and `long' at others?
                        Clearly the programmers who make the choices think there are --
                        or at least can be -- differences between int and long, and by
                        writing one or the other they express an intention about how they
                        want their variables to behave. To put the rhetorical question
                        even more crudely: If int and long are identical, why not just
                        eliminate `long' and flag it as an error?

                        Here's another, somewhat more abstract reason to pay attention
                        to type distinctions. To begin, we all know that `char' has the
                        same representation and behavior as `signed char' on some systems,
                        and as `unsigned char' on others. Yet even though `char' is "just
                        like" one or the other of these types, it is a type distinct from
                        both of them. By using plain `char', the programmer expresses a
                        preference that the machine use whichever type is "easier" for it
                        to deal with; the programmer does not need to commit to signed or
                        to unsigned and find that his code is unnecessarily slow on half
                        the machines that run it. That's why it is valuable to be able to
                        write `char' as distinct from `signed char' and `unsigned char',
                        even though it always behaves like one or the other. A distinction
                        that makes no difference on any one machine turns out to make a
                        difference when considering the wider universe of target machines.

                        Similar concerns motivate other types, too, which is why the
                        sizeof operator produces a size_t, why time() returns a time_t,
                        why sig_atomic_t exists, and so on. On any implementation you
                        can point at, these abstracted types (and others) are very likely
                        to be synonyms for various flavors of integers -- but for different
                        flavors on different systems. That's why portability is improved
                        by paying attention to type distinctions: They permit the programmer
                        to express his intentions to many platforms at once rather than to
                        just one at a time.
                        This are the reasons behind the decision. Some people like
                        heathfield or becarisse use this as a "proof that lcc-win is
                        useless", etc.
                        I don't recall seeing anyone describe lcc-win as "useless."
                        "Non-conforming," yes, but that's a different matter.
                        Note that lcc-win is not
                        just for pleasing pedants in comp.lang.c but it is useful
                        for doing REAL work.
                        It seems to me that "REAL" workers pay due attention to
                        portability, in light of the objectives of the project at hand.
                        A compiler that points out accidental strayings is helpful to
                        the programmers doing the REAL work, hence useful in that work.

                        --
                        Eric Sosman
                        esosman@ieee-dot-org.invalid

                        Comment

                        • Spiro Trikaliotis

                          #13
                          Re: When to emit diagnistics

                          jacob navia schrieb:
                          Joachim Schmitz wrote:
                          >Spiro Trikaliotis wrote:
                          [...]
                          >>warning level back to 3, but "disable language extensions" active:
                          [...]
                          >>This is exactly what I have expected.
                          >And the considerably younger VC 8.0, AKA Visual Studio 2005, is giving
                          >exatly the same warning, down to warning level 1, as long as language
                          >extension are disabled (i.e. working in conforming mode).
                          [...]
                          I did not know that you have to disable language extensions
                          to get a warning.
                          >
                          Anyway, that obscure option matches lcc -A -A obscure option.
                          For me, "disable language extensions" matches something like "--ansi"
                          (or similar).

                          Regards,
                          Spiro.

                          "Anybody who would spend considerable effort emulating a C64 is not
                          particularly sane to begin with; it is unreasonable to expect them to produce
                          sane software."
                          ("asuffield" in http://forums.thedailywtf.com/forums/p/7199/134136.aspx)

                          --
                          Spiro R. Trikaliotis http://opencbm.sf.net/
                          http://www.trikaliotis.net/ http://www.viceteam.org/

                          Comment

                          • jacob navia

                            #14
                            Re: When to emit diagnistics

                            Eric Sosman wrote:
                            This is a difficult notion for assembly programmers to grasp:
                            They tend to think about "type" in the way the hardware does, so
                            the idea of distinct types with identical behavior seems to them
                            obfuscatory. Angels on pinheads, academic piffle, and so on.

                            Pedants love that.

                            "char is different from signed char and unsigned char. It is another
                            type".

                            "int and long are different types even if they are the same in some
                            implementations "

                            And so on.

                            Yes, how CLEVER, how WELL you have mastered the C language, incredible.

                            I am just an "assembly language programmer". Obviously for you they
                            are kind of thick heads that have "difficulti es" grasping elementary
                            concepts like how many bugs can you fit in a pinhead.

                            Contrary to the pedants here that despise assembly and assembly
                            language programmers I write assembly every day. Even worst

                            o I generate assembly language from C input
                            o I assemble it
                            o I link it

                            Can you imagine that?

                            I *must* be a thick head then, obviously.


                            --
                            jacob navia
                            jacob at jacob point remcomp point fr
                            logiciels/informatique

                            Comment

                            • Eric Sosman

                              #15
                              Re: When to emit diagnistics

                              jacob navia wrote:
                              Eric Sosman wrote:
                              > This is a difficult notion for assembly programmers to grasp:
                              >They tend to think about "type" in the way the hardware does, so
                              >the idea of distinct types with identical behavior seems to them
                              >obfuscatory. Angels on pinheads, academic piffle, and so on.
                              >
                              >
                              Pedants love that.
                              >
                              "char is different from signed char and unsigned char. It is another
                              type".
                              >
                              "int and long are different types even if they are the same in some
                              implementations "
                              >
                              And so on.
                              >
                              Yes, how CLEVER, how WELL you have mastered the C language, incredible.
                              >
                              I am just an "assembly language programmer". Obviously for you they
                              are kind of thick heads that have "difficulti es" grasping elementary
                              concepts like how many bugs can you fit in a pinhead.
                              I've never said you have a thick head, not in this nor in
                              any other thread. Nor did I use the word "just" as in "mere"
                              or "only" to describe assembly language programmers; in fact,
                              I wrote "just" only three times altogether, none of them having
                              to do with programmers of any stripe.

                              What I wrote is that assembly language programmers have a
                              hard time understanding the importance of type, and I speculated
                              about the reason. That's my opinion, and by dismissing type as
                              pedantry you offer supporting evidence.
                              Contrary to the pedants here that despise assembly and assembly
                              language programmers
                              If you intend to include me among the despisers, you are
                              flat-out wrong. R-O-N-G, wrong.
                              I write assembly every day. Even worst
                              >
                              o I generate assembly language from C input
                              o I assemble it
                              o I link it
                              >
                              Can you imagine that?
                              >
                              I *must* be a thick head then, obviously.
                              Not a thick head, but an extraordinarily thin skin.

                              --
                              Eric.Sosman@sun .com

                              Comment

                              Working...