Re: Semantic Checking - C

jacob navia <jacob@jacob.remcomp.fr>
3 Feb 2005 22:42:27 -0500

          From comp.compilers

Related articles
Semantic Checking - C johnvoltaire@gmail.com (johnvoltaire) (2005-01-30)
Re: Semantic Checking - C nmm1@cus.cam.ac.uk (2005-02-03)
Re: Semantic Checking - C torbenm@diku.dk (2005-02-03)
Re: Semantic Checking - C jeremy.wright@microfocus.com (Jeremy Wright) (2005-02-03)
Re: Semantic Checking - C jacob@jacob.remcomp.fr (jacob navia) (2005-02-03)
Re: Semantic Checking - C neal.wang@gmail.com (Neal Wang) (2005-02-03)
Re: Semantic Checking - C foobar@nowhere.void (Tommy Thorn) (2005-02-03)
Re: Semantic Checking - C hannah@schlund.de (2005-02-11)
| List of all articles for this month |

From: jacob navia <jacob@jacob.remcomp.fr>
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
lcclnk.


> 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:


printf("hello\n");


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
(redefinition).


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


Feel free to write me if you want further details.


lcc-win32: http://www.cs.virginia.edu/~lcc-win32


Post a followup to this message

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