UMBC CMSC 201 Spring '05 CSEE | 201 | 201 S'05 | lectures | news | resources |discussion| help

Compiler Errors

  • The compiler is your friend.
  • It's error messages are helpful advice, not complaints or admonishments.
  • Its just not very tactful, that's all.

Read the Compiler Errors

Messages like :

linux3[77] % gcc -Wall -ansi sample.c
sample.c: In function `main':
sample.c:30: parse error before `printf'
sample.c:36: warning: control reaches end of non-void function
linux3[78] % 

tell you where to look.

Here are the lines of sample.c from line 26 to 36 :


   /* Display the largest integer entered */
   if(largest == 0)
   {
      printf("\nYou quit right away!  No integer to")
      printf(" display.\n");
   }
   else
   {
      printf("\nThe largest integer entered was %d.\n", largest);
   }
}

The first error :
sample.c:30: parse error before `printf'
Says before the word printf on line 30 there was a parse error. Since printf is the first word on line 30, you need to examine the previous line. Sure enough there is a missing semicolon on line 29.

There is also a warning message:

sample.c:36: warning: control reaches end of non-void function
Line 36 is the closing brace of main and the warning means that something needs to be returned instead of the function just ending. Adding return 0; will fix this problem.

Instead of cutting or commenting out every line that comes up with an error, it's important to try to understand what's causing that error.

But How Do I Get My Editor To Tell Me What Line Number I'm On?

In xemacs, the command [ESC]-x line (press escape, press x, then type the word line and hit enter) will turn on the line numbering. The line you're on will appear on the bottom bar. Like this :

ISO8--**-XEmacs: sample.c  (C Font)----L30--All----------------
To jump to a line, the command [ESC]-x goto line (press escape, press x, then type the two words goto line and hit enter) will prompt you for the line number you want to go to. Then type in the line number and hit enter.

Alternatively, you can invoke the next line (^N) command with an argument, for example

u25n

goes down 25 lines.

In vi, the command [CTRL]->g (hold down the control key while pressing "g") will show you what line you are on. To jump to a line, type in the line number and then press "G".


CSEE | 201 | 201 S'05 | lectures | news | resources | help |

Monday, 18-Apr-2005 13:41:42 EDT