Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Static checking of C programs with LCLint

Reply
Thread Tools

Static checking of C programs with LCLint

 
 
aarklon@gmail.com
Guest
Posts: n/a
 
      04-14-2008
Hi all,


see:-
http://linuxgazette.net/issue51/pramode.html
 
Reply With Quote
 
 
 
 
user923005
Guest
Posts: n/a
 
      04-14-2008
On Apr 14, 8:04*am, Richard Heathfield <(E-Mail Removed)> wrote:
> (E-Mail Removed) said:
>
> > Hi all,

>
> > see:-
> >http://linuxgazette.net/issue51/pramode.html

>
> From that page: "Here is a small C program:
>
> main()
> {
> * * * * int a[10];
> * * * * if (sizeof(a)/sizeof(a[0]) > -1)
> * * * * * * printf("hello\n");
>
> }
>
> *We expected this to print hello, but it did not."
>
> You might have expected that, but I didn't. I expected it to exhibit
> undefined behaviour.
>
> "gcc did not give us any hint."
>
> Really?
>
> foo.c:2: warning: return-type defaults to `int'
> foo.c:2: warning: function declaration isn't a prototype
> foo.c: In function `main':
> foo.c:4: warning: comparison between signed and unsigned
> foo.c:5: warning: implicit declaration of function `printf'
> foo.c:6: warning: control reaches end of non-void function
>
> That looks like quite a few hints to me.


Then again, the article is 7 years old and it was even before the name
change from LCLint to SPLint.
I guess it would have been GCC 2.95 or so back then.
 
Reply With Quote
 
 
 
 
David Thompson
Guest
Posts: n/a
 
      04-28-2008
On Mon, 14 Apr 2008 15:04:15 +0000, Richard Heathfield
<(E-Mail Removed)> wrote:

> http://www.velocityreviews.com/forums/(E-Mail Removed) said:


> > http://linuxgazette.net/issue51/pramode.html

>
> From that page: "Here is a small C program:
>
> main()
> {
> int a[10];
> if (sizeof(a)/sizeof(a[0]) > -1)
> printf("hello\n");
> }
>
> We expected this to print hello, but it did not."
>
> You might have expected that, but I didn't. I expected it to exhibit
> undefined behaviour.
>

I didn't, unless size_t is narrower than signed int (which is
permitted, but rarely sensical). Otherwise, the printf call is never
executed, and has no opportunity to cause UB.

In C<99 it does produce unspecified exit status, which is bad, but not
UB. The other style points are also bad style but not UB.

- formerly david.thompson1 || achar(64) || worldnet.att.net
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking Perl 5.8.0 programs. RedGrittyBrick Perl Misc 1 06-23-2010 01:48 PM
Programs take a long time to launch from A.Programs Me MCSE 9 01-20-2005 04:05 PM
executing multiple perl programs sequentially and checking return values for errors brad Perl Misc 3 01-15-2004 09:39 PM
How to uninstall LCLint? Christoph W. Lueken C Programming 1 08-24-2003 03:01 AM
Re: How to see all programs after Start -> All Programs Ben Leal Computer Support 1 08-06-2003 01:58 AM



Advertisments