Re: [Freeciv-Dev] Programing style
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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;
}
|
|