|
Syntax errors in C
|
|
12-04-2009, 01:14 PM
Post: #1
|
|||
|
|||
|
Syntax errors in C
Errors in the syntax, or word structure of a program are caught before you run it, at compilation time by the compiler program. They are listed all in one go, with the line number, in the text file, at which the error occurred and a message to say what was wrong.
For example, suppose you write sin (x) y = ; in a program instead of y = sin (x);, which assigns the value of the sin of x to y. Upon compilation, you would see this error message: eg.c: In function `main': eg.c:12: parse error before `y' (If you compile the program in Emacs, you can jump directly to the error.) A program with syntax errors will cause a compiler program to stop trying to generate machine code and will not create an executable. However, a compiler will usually not stop at the first error it encounters but will attempt to continue checking the syntax of a program right to the last line before aborting, and it is common to submit a program for compilation only to receive a long and ungratifying list of errors from the compiler. It is a shock to everyone using a compiler for the first time how a single error can throw the compiler off course and result in a huge and confusing list of non-existent errors, following a single true culprit. The situation thus looks much worse than it really is. You'll get used to this with experience, but it can be very disheartening. As a rule, look for the first error, fix that, and then recompile. Of course, after you have become experienced, you will recognize when subsequent error messages are due to independent problems and when they are due to a cascade. But at the beginning, just look for and fix the first error. |
|||
|
« Next Oldest | Next Newest »
|
Search
Member List
Calendar
Help


