Re: How to check if same partition



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:

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

yes but if you do something like this:

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.



.



Relevant Pages

  • xemacs installation problems
    ... checking for gcc... ... checking whether we are using GNU C... ... checking size of int... ... configure: warning: No OffiX without generic Drag'n'Drop support ...
    (comp.os.linux.misc)
  • Help needed in solving C-errors in Linux (gcc)
    ... i'm trying to make I got the following messages from gcc. ... main.c:22: warning: comparison is always false due to limited range of data type ... int conv_inch2feet; ... int convert(int unit, const char *,const char *,const char *); ...
    (comp.os.linux.development.apps)
  • Help needed in solving C-errors in Linux (gcc)
    ... i'm trying to make I got the following messages from gcc. ... main.c:22: warning: comparison is always false due to limited range of data type ... int conv_inch2feet; ... int convert(int unit, const char *,const char *,const char *); ...
    (alt.os.linux)
  • Re: [ofa-general] [PATCH 2.6.30] RDMA/cxgb3: Remove modulo math.
    ... sparc with -O2, for the test program: ... int main(int argc) ... (u32 is unsigned int on all Linux architectures). ... although gcc 4.1 does do a div instead of an and. ...
    (Linux-Kernel)
  • Re: Any differnece between functions
    ... int main ... a warning for main. ... If you don't use argc and argv, ... being returned to the host environment. ...
    (comp.lang.c)