Complete.Org: Mailing Lists: Archives: freeciv-dev: June 1999:
Re: [Freeciv-Dev] Programing style
Home

Re: [Freeciv-Dev] Programing style

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jmlb2@xxxxxxxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx
Subject: Re: [Freeciv-Dev] Programing style
From: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Date: Thu, 10 Jun 1999 21:30:47 +1000 (EST)

Jules Bean wrote:

> If you *want* lots of warnings, -Wall is still a better idea than
> -pedantic.

Nah, that doesn't give lots of warnings: freeciv is already -Wall 
clean on my linux box :-)  (I usually use "-Wall -Werror".)

(Well, except for the suspected gcc (egcs) bug I noted before,
if you use -O2.  Attached is a demo prog which demonstrates the
buggy warning; Debian 2.1, gcc 2.91.66-1)

-- David
/*
  
$ gcc  -O2 -Wall twarn.c 
twarn.c: In function `get_bar':
twarn.c:22: warning: `xfoo' might be used uninitialized in this function
$ gcc  -Wall twarn.c 
$ gcc  -O2 -Wall twarn.c -DAOK
$

*/

#include <stdio.h>
#include <stdlib.h>

#define NUM 100

int n_arr[NUM];
int *arr[NUM]; 

int get_bar(int a)
{
  int xfoo, i;

#ifndef AOK
  if( (a<0) || (a>=NUM) ) {
    exit(1);
  }
#endif
  
  for(i=0; i<n_arr[a]; i++) {
    xfoo = arr[a][i];
    if(xfoo) {
      return xfoo;
    }
  }
  return -1;
}

void initer(void)
{
  int i;
  for(i=0; i<NUM; i++) {
    n_arr[i] = 30;
    arr[i] = calloc(n_arr[i],sizeof(int));
  }
}

int main(void)
{
  initer();
  printf("%d\n", get_bar(3));
  return EXIT_SUCCESS;
}

[Prev in Thread] Current Thread [Next in Thread]