Amiga.org
Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: ChaosLord on September 09, 2004, 07:47:04 PM
-
How do I stop all these insane warnings?
Do all C Compilers do this? Or just SASC?
int count,color[256],halfcolor[256];
// I put this loop here to try to
// stop jillions of 'possibly uninitialized variable "color"' warnings
// BUT IT HAS NO EFFECT!
FOR (count=0;count<=256; count++) DO
color[count]=0; halfcolor[count]=0;
NEXT // count++
Here are the warnings I get when I compile with optimize=on
info.c 313 Warning 317: possibly uninitialized variable "color"
info.c 321 Warning 317: possibly uninitialized variable "halfcolor"
info.c 328 Warning 317: possibly uninitialized variable "halfcolor"
info.c 335 Warning 317: possibly uninitialized variable "color"
info.c 338 Warning 317: possibly uninitialized variable "color"
info.c 343 Warning 317: possibly uninitialized variable "color"
info.c 349 Warning 317: possibly uninitialized variable "halfcolor"
info.c 352 Warning 317: possibly uninitialized variable "halfcolor"
info.c 357 Warning 317: possibly uninitialized variable "halfcolor"
info.c 362 Warning 317: possibly uninitialized variable "halfcolor"
info.c 365 Warning 317: possibly uninitialized variable "halfcolor"
info.c 370 Warning 317: possibly uninitialized variable "halfcolor"
info.c 376 Warning 317: possibly uninitialized variable "color"
info.c 379 Warning 317: possibly uninitialized variable "color"
info.c 382 Warning 317: possibly uninitialized variable "color"
info.c 387 Warning 317: possibly uninitialized variable "color"
info.c 390 Warning 317: possibly uninitialized variable "color"
info.c 397 Warning 317: possibly uninitialized variable "halfcolor"
info.c 400 Warning 317: possibly uninitialized variable "halfcolor"
info.c 403 Warning 317: possibly uninitialized variable "halfcolor"
info.c 408 Warning 317: possibly uninitialized variable "halfcolor"
info.c 411 Warning 317: possibly uninitialized variable "halfcolor"
info.c 417 Warning 317: possibly uninitialized variable "halfcolor"
info.c 420 Warning 317: possibly uninitialized variable "halfcolor"
info.c 423 Warning 317: possibly uninitialized variable "halfcolor"
info.c 428 Warning 317: possibly uninitialized variable "halfcolor"
info.c 431 Warning 317: possibly uninitialized variable "halfcolor"
I don't want to use ignore=317
I want to be warned about REAL possibly uninitialized variables.
color and halfcolor ARE initialized.
How can I stop these fake warnings without stopping the real
warnings?
-
color and halfcolor *aren't* initialized--they're only declared. You'll need to do something like this to get rid of the warning:
int count = 256, color[256] = {0}, halfcolor[256] = {0};
Or,
#define COUNT 256
fn()
{
int color[COUNT] = {0}, halfcolor[COUNT] = {0};
}
Are FOR, DO, and NEXT SASC-specific macros? Using a standard C for-loop might disable the warning as well, but initializing the variables as part of the declaration should allow the compiler to do the optimization for you.
Trev
-
I've observed that SAS/C is sometimes 'overprotective' in case of uninitialized variables, but at least from my observations, it happened mostly with conditional instructions, like:
int i;
int j;
/* blablabla */
if( i == 0 ) {
j = 0; // initailized really conditionally
}
if( i == 0 ) {
printf( "%d", j ); // whenever used its always initialized
}
In this case it is hard to judge, just having list of warnings and sample of code to prove its wrong. Sometimes That Important Something is hidden in the place of code we do not expect it at all.
However I don't know really - mayby it is just like so. By the way - which version of SAS/C are you using?
Anyway one VERY IMPORTANT COMMENT FROM ME:
FOR (count=0;count<=256; count++) DO
carefull PLEASE(!!!):
count < 256
-
carefull PLEASE(!!!):
count < 256
u r correct. silly me. :) thanx
-
@Trev
Thank u very much! Problem solved thanx 2 ur professional insight.
I ur friend for life! or 1 week, whichever comes first 8D