This is a wrong code.I just want to know how it affect the compiler,becausethe error message is quite strange.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?GB2312?B?yum09MXt?=

    This is a wrong code.I just want to know how it affect the compiler,becausethe error message is quite strange.


    today I forgot to include some header,then I found the error message by the compiler is quite strange.

    so I want to know exactly the inner details of the compiler impletation,if possible.

    and I want to know what does the standard say about this situation.


    here is the code just to demonstrate the error.


    int main()
    {
    new int; // this is OK
    new someClass; // yeah,I know this is wrong because someClass is not declared.

    return 0;
    }

    the Visual C++ 6.0 compiler said:

    D:\test1\test1. cpp(12) : error C2061: syntax error : identifier 'someClass'
    D:\test1\test1. cpp(15) : error C2143: syntax error : missing ';' before '}'
    D:\test1\test1. cpp(15) : error C2143: syntax error : missing ';' before '}'
    ....
    D:\test1\test1. cpp(15) : fatal error C1003: error count exceeds 100; stopping compilation


    where the "..." represent 97 messages of "error C2143: syntax error : missing ';' before '}' "

    so I guess something made the compiler drop into a infinitive recursion .

    but I dont know why.

    please tell me if you just know the reason.

    if you dont have time,just ignore this.

    thanks very much.
  • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

    #2
    Re: This is a wrong code.I just want to know how it affect the compiler,becaus ethe error message is quite strange.

    On 2008-10-18 16:17, 书呆彭 wrote:
    today I forgot to include some header,then I found the error message by the compiler is quite strange.
    >
    so I want to know exactly the inner details of the compiler impletation,if possible.
    >
    and I want to know what does the standard say about this situation.
    >
    >
    here is the code just to demonstrate the error.
    >
    >
    int main()
    {
    new int; // this is OK
    new someClass; // yeah,I know this is wrong because someClass is not declared.
    >
    return 0;
    }
    >
    the Visual C++ 6.0 compiler said:
    >
    D:\test1\test1. cpp(12) : error C2061: syntax error : identifier 'someClass'
    D:\test1\test1. cpp(15) : error C2143: syntax error : missing ';' before '}'
    D:\test1\test1. cpp(15) : error C2143: syntax error : missing ';' before '}'
    ...
    D:\test1\test1. cpp(15) : fatal error C1003: error count exceeds 100; stopping compilation
    >
    >
    where the "..." represent 97 messages of "error C2143: syntax error : missing ';' before '}' "
    >
    so I guess something made the compiler drop into a infinitive recursion .
    >
    but I dont know why.
    Because VC++ 6 is old and buggy and I would not use unless I had no
    other choice. A more recent version of the compiler only emits one error
    message.

    --
    Erik Wikström

    Comment

    • =?UTF-8?B?5Lmm5ZGG5b2t?=

      #3
      Re: This is a wrong code.I just want to know how it affect the compiler,becaus ethe error message is quite strange.

      Erik Wikström 写道:

      Because VC++ 6 is old and buggy and I would not use unless I had no
      other choice. A more recent version of the compiler only emits one error
      message.
      Then is that message " error C2143: syntax error : missing ';' before '}'"

      Comment

      • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

        #4
        Re: This is a wrong code.I just want to know how it affect the compiler,becaus ethe error message is quite strange.

        On 2008-10-18 17:47, 书呆彭 wrote:
        Erik Wikström 写道:
        >
        >>
        >Because VC++ 6 is old and buggy and I would not use unless I had no
        >other choice. A more recent version of the compiler only emits one error
        >message.
        >>
        >
        Then is that message " error C2143: syntax error : missing ';' before '}' "
        As a rule, you can only trust the first error message a compiler (any
        compiler) emits, all after might be the result of the compiler being
        thrown of by the first error.

        --
        Erik Wikström

        Comment

        • =?UTF-8?B?5Lmm5ZGG5b2t?=

          #5
          Re: This is a wrong code.I just want to know how it affect the compiler,becaus ethe error message is quite strange.

          Erik Wikström 写道:
          On 2008-10-18 17:47, 书呆彭 wrote:
          >Erik Wikström 写道:
          >>
          >>Because VC++ 6 is old and buggy and I would not use unless I had no
          >>other choice. A more recent version of the compiler only emits one error
          >>message.
          >>>
          >Then is that message " error C2143: syntax error : missing ';' before '}' "
          As a rule, you can only trust the first error message a compiler (any
          compiler) emits, all after might be the result of the compiler being
          thrown of by the first error.
          I very appreciate your help.
          I got it.
          Thank you again.

          Comment

          • Juha Nieminen

            #6
            Re: This is a wrong code.I just want to know how it affect the compiler,becaus ethe error message is quite strange.

            Erik Wikström wrote:
            As a rule, you can only trust the first error message a compiler (any
            compiler) emits, all after might be the result of the compiler being
            thrown of by the first error.
            Which raises the question: Why do compilers bother with the rest of
            the errors? Why not just stop with the first error?

            Comment

            • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

              #7
              Re: This is a wrong code.I just want to know how it affect the compiler,becaus ethe error message is quite strange.

              On 2008-10-19 12:04, Juha Nieminen wrote:
              Erik Wikström wrote:
              >As a rule, you can only trust the first error message a compiler (any
              >compiler) emits, all after might be the result of the compiler being
              >thrown of by the first error.
              >
              Which raises the question: Why do compilers bother with the rest of
              the errors? Why not just stop with the first error?
              Because sometimes they are reliable and fixing more than one error
              between recompiles is nice. After using a compiler for some time you can
              generally tell which errors are due to earlier errors and which are
              genuine errors.

              --
              Erik Wikström

              Comment

              • James Kanze

                #8
                Re: This is a wrong code.I just want to know how it affect thecompiler,bec ause the error message is quite strange.

                On Oct 19, 12:26 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
                On 2008-10-19 12:04, Juha Nieminen wrote:
                Erik Wikström wrote:
                As a rule, you can only trust the first error message a
                compiler (any compiler) emits, all after might be the
                result of the compiler being thrown of by the first error.
                Which raises the question: Why do compilers bother with the
                rest of the errors? Why not just stop with the first error?
                Would you use such a compiler?
                Because sometimes they are reliable and fixing more than one
                error between recompiles is nice. After using a compiler for
                some time you can generally tell which errors are due to
                earlier errors and which are genuine errors.
                Resynchronizing after an error is one of the most difficult
                things in compiler construction; you want to absorb (and throw
                out) enough input to avoid follow-up errors, but you don't want
                to miss any real errors after the detected error. In this case,
                the compiler was obviously not throwing out enough, keeping both
                the partially parsed new expression, and the next token. In the
                end, the only thing that stopped it was a hard wired maximum
                number of errors. (Most compilers do this as well, as a safety
                net. After all, what's the use of going on if the actual error
                was that you fed an Ada program to the C++ compiler?)

                --
                James Kanze (GABI Software) email:james.kan ze@gmail.com
                Conseils en informatique orientée objet/
                Beratung in objektorientier ter Datenverarbeitu ng
                9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                Comment

                • Hendrik Schober

                  #9
                  Re: This is a wrong code.I just want to know how it affect the compiler,becaus ethe error message is quite strange.

                  James Kanze wrote:
                  On Oct 19, 12:26 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
                  >On 2008-10-19 12:04, Juha Nieminen wrote:
                  >
                  >>Erik Wikström wrote:
                  >>>As a rule, you can only trust the first error message a
                  >>>compiler (any compiler) emits, all after might be the
                  >>>result of the compiler being thrown of by the first error.
                  >
                  >>Which raises the question: Why do compilers bother with the
                  >>rest of the errors? Why not just stop with the first error?
                  >
                  Would you use such a compiler?
                  >
                  >Because sometimes they are reliable and fixing more than one
                  >error between recompiles is nice. After using a compiler for
                  >some time you can generally tell which errors are due to
                  >earlier errors and which are genuine errors.
                  >
                  Resynchronizing after an error is one of the most difficult
                  things in compiler construction; you want to absorb (and throw
                  out) enough input to avoid follow-up errors, but you don't want
                  to miss any real errors after the detected error. [...]
                  Well, probably even more important, you don't want to miss a
                  closing brace or parenthesis.

                  Schobi

                  Comment

                  Working...