Menu

tydef help

2003-02-03
2012-09-26
  • Nobody/Anonymous

    The following code throws up parse errors, can anyone tell me why?

    // Demonstration of variables
    #include <iostream>
    using namespace std;
    #include <stdlib.h>

    typedef unsigned short int USHORT;  //typedef defined

    int main()
    {
        USHORT Width = 5,
        USHORT Length;
        Length = 10;
       
        //create an unsigned short and initialize with result
        //of multiplying width by length
        USHORT Area = Width * Length;
       
        cout << "Width: " << Width << "\n";
        cout << "Length: " << Length << endl;
        cout << "Area: " << Area << endl;
        system("pause");
        return 0;
    }

     
    • Curtis Sutter

      Curtis Sutter - 2003-02-03

      USHORT Width = 5,

      You have a , instead of a ;

      would test that theory, but don't have Dev re-installed yet

      Curtis
      P.S.  Dbl clicking on the error/Warning, should highlight the conflicting line.  It also tells you the line #

       
    • Nobody/Anonymous

      Yes, Curtis is right on,  fix the , to a ;, and it works perfectly.

      Parse errors, for me at least, ase usually missing ; or unpaired {} or ().

      This also points our the importance of looking at first errors first, the ; error tripped multiple errors, fixing the ; fixed them all.  Note my compile log with the error:

      Compiler: Default compiler
      Executing  g++.exe...
      g++.exe "C:\Dev-Cpp\testit.cpp" -o "C:\Dev-Cpp\testit.exe"    -I"C:\Dev-Cpp\include\c++"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"
      C:/Dev-Cpp/testit.cpp: In function `int main()':
      C:/Dev-Cpp/testit.cpp:11: parse error before `;' token

      C:/Dev-Cpp/testit.cpp:12: `Length' undeclared (first use this function)
      C:/Dev-Cpp/testit.cpp:12: (Each undeclared identifier is reported only once for
         each function it appears in.)
      C:/Dev-Cpp/testit.cpp:16: `USHORT' undeclared (first use this function)
      C:/Dev-Cpp/testit.cpp:16: parse error before `=' token
      C:/Dev-Cpp/testit.cpp:20: `Area' undeclared (first use this function)

      Execution terminated

      Wayne

       
    • Anonymous

      Anonymous - 2003-02-03

      Ditto. The error messages contain INFORMATION  -don't be scared, read them! (Although I admit, plain English is often not the compiler's strong point - but the line number will tell you where to start looking).

      Clifford

       
    • Nobody/Anonymous

      Or, if ytou double click on the error message, it takes you to the line in question.

      Note that missing ; can be tricky, the error might show up much later in the code...

      Wayne

       
    • Nobody/Anonymous

      It now works fine. I just could not see that "," i must have been going code blind.

      Thanks people.

       
    • Curtis Sutter

      Curtis Sutter - 2003-02-04

      np

      Curtis

       
    • Nobody/Anonymous

      I *never* do anything like that!

      *Lightening strikes*

      Wayne

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.