On Tue, 05 Aug 2008 01:10:25 +0200
Javier Martín <[EMAIL PROTECTED]> wrote:
> Besides, sometimes checks like "if (a=b)", or more
> frequently "if (a=f())" are intentionally used in C, so the error
> might become even more difficult to spot and correct.
Respect and heed the gcc warnings!!
Note that gcc will warn you (you *are* using -Wall, at least, right?)
if you try to do
if (a = b)
but if you really mean it, you should surround the expression with an
extra pair of parentheses:
if ((a = b))
Use of the value of an assignment in an expression is common in code
like
if ((n = read (fd, buf, sz)) > 0)
/* ... use the data in buf ... */
Here's an example showing gcc being helpful:
$ cat a.c
int f()
{
int a = 1;
int b;
if ((b = a))
return 1;
return 0;
}
$ cat b.c
int f()
{
int a = 1;
int b;
if (b = a)
return 1;
return 0;
}
$ gcc -Wall -c a.c
$ gcc -Wall -c b.c
b.c: In function ‘f’:
b.c:5: warning: suggest parentheses around assignment used as truth
$
> New version of the patch follows. I must say that the discussion here
> has become pretty interesting without degrading into flamewarring -
> who whats to call Mr. Torvalds and Prof. Tanembaum? ^^
Well, it sounds to me like you are trying your best to set Marco ablaze,
but he is delightfully fire-retardant.
Regards,
Colin
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel