Re: How to check if same partition
- From: Jan Panteltje <pNaonStpealmtje@xxxxxxxxx>
- Date: Sat, 03 Jun 2006 11:30:59 GMT
On a sunny day (2 Jun 2006 16:33:58 -0700) it happened "Markus Schoder"
<a3vr6dsg-usenet@xxxxxxxx> wrote in
<1149291238.313797.66810@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>:
Jan Panteltje wrote:
On a sunny day (Fri, 02 Jun 2006 05:10:14 -0700) it happened Eric
<NoOne@xxxxxxxxxxx> wrote in <2audnS8bzYk7tx3ZnZ2dnUVZ_vGdnZ2d@xxxxxxxxxxx>:
Erik de Castro Lopo wrote:yes but if you do something like this:
Michel Bardiaux wrote:
Found my problem, it was a bad "if" (the classic case you get when you
dont use curlies *always*). Definitely getting old...
If you use the -W and -Wall warning flags (and fix all warnings)
GCC will bitch when you get this wrong.
Erik
Even better is to add -Werror
Ignoring warnings usually leads to problems later on.
Eric
function(int b, int c, int something)
{
int a, b;
if(something) {if(b == 1) a = 1; else a = 2; return a;}
return b * c;
}
gcc wil say:
Abort error, 'a' may be undefined in ....
So then you have to declare all vars like:
int a = 0;
The gcc version I am using is clever enough not to give this warning
for this case.
I have had the warning many times, but indeed this example was not cut
and paste, but once I wrote from what I remembered from the last time.
The following code triggers it however (with at least -O1):
extern void g(void);
int f(int b)
{
int a;
if(b) a = 1;
g();
return b ? a : 0;
}
Seems that gcc thinks that g() can modify the local variable b.
Yes...
This will do it too:
something(int a)
{
int a;
int b;
if(a == 1) b = 1;
else if(a == 2) b = 3;
return b;
}
It is an incomplete switch, the programmer knows a can only take 2 values,
but gcc does not.
Now let's see if gcc is really smart:
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int b;
printf("argc=%d\n", argc);
if( (argc < 1) || (argc > 2) )
{
printf("aborting.\n");
return 1;
}
if(argc == 1) b = 1;
else if(argc == 2) b = 3;
return b;
}
gcc -v:
gcc version 3.3.6 (Debian 1:3.3.6-12):
grml: ~ # gcc -O2 -Wall -o test2 test2.c
test2.c: In function `main':
test2.c:7: warning: `b' might be used uninitialized in this function
gcc version 4.0.3 20060104 (prerelease) (Debian 4.0.2-6):
grml: ~ # gcc -O2 -Wall -o test2 test2.c
test2.c: In function 'main':
test2.c:7: warning: 'b' may be used uninitialized in this function
This is not true! I covered all cases for argc.
So, YMMV, but gcc is not really evaluation the code I think.
.
- Follow-Ups:
- Re: How to check if same partition
- From: Markus Schoder
- Re: How to check if same partition
- References:
- Re: How to check if same partition
- From: Eric
- Re: How to check if same partition
- From: Jan Panteltje
- Re: How to check if same partition
- From: Markus Schoder
- Re: How to check if same partition
- Prev by Date: Re: win32 + widget set + rsvg integration + portable apps
- Next by Date: Re: How to check if same partition
- Previous by thread: Re: How to check if same partition
- Next by thread: Re: How to check if same partition
- Index(es):
Relevant Pages
|