Re: Semantic Checking - C

jacob navia <>
3 Feb 2005 22:42:27 -0500

          From comp.compilers

Related articles
Semantic Checking - C (johnvoltaire) (2005-01-30)
Re: Semantic Checking - C (2005-02-03)
Re: Semantic Checking - C (2005-02-03)
Re: Semantic Checking - C (Jeremy Wright) (2005-02-03)
Re: Semantic Checking - C (jacob navia) (2005-02-03)
Re: Semantic Checking - C (Neal Wang) (2005-02-03)
Re: Semantic Checking - C foobar@nowhere.void (Tommy Thorn) (2005-02-03)
Re: Semantic Checking - C (2005-02-11)
| List of all articles for this month |

From: jacob navia <>
Newsgroups: comp.compilers
Date: 3 Feb 2005 22:42:27 -0500
Organization: les newsgroups par Wanadoo
References: 05-01-098
Keywords: C, debug
Posted-Date: 03 Feb 2005 22:42:27 EST

Here are some hints from the lcc-win32 compiler

johnvoltaire wrote:
> Common semantic errors in C language:
> 1. Use of function without function prototypes

lcc-win32 reports this as a warning.

> 2. Code with no effect (dead code)

lcc-win32 reports an assignment that is not used further
in the program. Other dead code could be reported if more
was done in this direction.

> 3. Division by zero

This is detected at compile time when the division is made
by two compile-time constants. Code could be generated at
run time to check division.

> 4. Use of functions and variables which are defined but not used

lcc-win32 reports this when the function/variable is static.
For non-static variables, this is done by the lcc-win32's linker

> 5. Use of functions and variables with defined arguments that are never
> used
This is reported and easy to detect.

> 6. Use of functions and variables that return either with or without
> any assigned value

A warning is issued when a function declared as returning a value
doesn't return one.

> 7. Use of functions and variables that return values that are never
> used

This is not reported but could be done. If you want this, it would be
very difficult, since this is common practice:


doesn't use the return value of printf but it is valid code.

> 8. Subscript out of bounds

I have been arguing in this group (and in the standards discussion
group) about the necessity of doing this. The problem is that
you would need a new kind of pointers, (bounded pointers) that
would carry size information.

> 9. Booleans that always evaluate true or evaluate false

lcc-win32 forces this. Any boolean is casted to 1 or zero.

> 10. Checking of infinite loops as well as loops that cannot be exited
> or entered

lcc-win32 checks this.

> 11. Statements that cannot be reached during execution
lcc-win32 checks this

> 12. No identifiers or variables are used twice in the same block or
> scope

lcc-win32 will warn you that a higher scope variable is shadowed
if you request this type of warnings.

> 13. The number and types of arguments in a function call must be the
> same as the number and types of the prototypes

This is checked

> 14. A return statement must not have a return value unless it appears
> in the function prototype that is declared to return a value

The same as item 6.

> 15. Break statements appear outside enclosing constructs where a break
> statement may appear

This is a syntax error

> 16. Elements of enumerated types are repeated

This is an error. It stops compilation.

> 17. Variable names appear in the same lexical scope

I suppose that you mean identical variable names. This is an error

> 18. Labels are repeated
The same error as 15: redefinition, syntax error. Compilation stops

Feel free to write me if you want further details.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.