www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/18/12:51:22

From: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
Newsgroups: comp.os.msdos.djgpp
Subject: Lint for DJGPP
Date: Wed, 18 Sep 1996 14:51:07 +0100
Organization: Lehrstuhl fuer Stroemungsmechanik
Lines: 83
Message-ID: <323FFE4B.1CFB@LSTM.Ruhr-UNI-Bochum.De>
NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Someone asked a few days ago about a lint for djgpp C
A free version is available from
ftp://larch.lcs.mit.edu/pub/Larch/lclint
The source is available, so it should compile and
run under DOS.

Well, Eli said gcc -Wall -pedantic usually suffices, 
here is a little riddle. The following program contains
11 bugs/flaws. gcc finds 7. How many do YOU find? ;-)

>>>>> snip >>>>>>>>>>
/* main prog bsp.c:
 * print square numbers from "lower" to "upper".
 * Range given from commandline
 */
#include <stdio.h>
#include <stdlib.h>
extern int lower, upper;
extern void print_table(int, int);

static const char *PROG;        /* program name */
static void SHOW_USAGE()        /*  how to use */
{
   (void) printf((stderr,"Usage: %s [ [lower ] upper ]\n"),
                   PROG);
    exit();
}

int main(int argc, char *argv[])   /* MAIN PROGRAM */
{
    /* Set program name for usage * /
    PROG = argv[0];   /* in SHOW_USAGE */
    
    if(argc > 3)  
       SHOW_USAGE;
    else {
      /*  get upper limit if given */
      if(argc >= 2)
        upper = atoi(argv[argc-1]);
      /* get lower if given */
      if (argc == 3);
      lower=atof(argv[1]);
      /* print table and exit */
      print_table(lower, upper);
      return 0;
    }
} 
 
/*
 * PRINTING FUNCTION
 */
#include <stdio.h>   

int lower = 1;
int upper = 100;

int print_table(int lo, int hi)
{   int i;
     while(lower < upper)
       (void) printf("%7d ",++lower*lower);
     if ( i % 10  == 0)
        (void) printf("\n");
     return i;
}
<<<< snap <<<<<<<<<<

BTW, I found 8.

-- 
Ciao
Tom

*************************************************************
* Thomas Demmer                                             *
* Lehrstuhl fuer Stroemungsmechanik                         *
* Ruhr-Uni-Bochum                                           *
* Universitaetsstr. 150                                     *
* D-44780  Bochum                                           *
* Tel: +49 234 700 6434                                     *
* Fax: +49 234 709 4162                                     *
* Voice/Fax Box: +49 2561 91371 2056                        *
* http://www.lstm.ruhr-uni-bochum.de/~demmer                *
*************************************************************

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019