Re: [PATCH][2.6.6-rc3] gcc-3.4.0 fixes

From: Paul Wagland
Date: Thu Apr 29 2004 - 15:53:57 EST



On Apr 29, 2004, at 11:30, Ihar 'Philips' Filipau wrote:

Mikael Pettersson wrote:
This patch fixes three warnings from gcc-3.4.0 in 2.6.6-rc3:
- drivers/char/ftape/: use of cast-as-lvalue
if (get_unaligned((__u32*)ptr)) {
- ++(__u32*)ptr;
+ ptr += sizeof(__u32);
} else {

Can anyone explain what is the problem with this?
To me it seems pretty ligitimate code - why it was outlawed in gcc 3.4?

http://es-sun2.fernuni-hagen.de/cgi-bin/info2html?(gcc)Subscripting

The ability to manipulate a cast was always a gcc extension, whether by design or feature I am not sure. The problem is that it breaks C++ templates in a bad way. Here is where the extension is documented for GCC 3.3.3

http://gcc.gnu.org/onlinedocs/gcc-3.3.3/gcc/Lvalues.html

This extension is now obsoleted.

Previous code was agnostic to type of ptr, but you code presume ptr being char pointer (to effectively increment by 4 bytes).

Yes, and the previous code assumed that that ptr was not a pointer to a 64 bit value, since dereferencing it on most platforms would then explode. I bet that both assumptions are just as safe ;-) However if you really wanted to be safe then you could do

ptr += sizeof (__32) / sizeof (*ptr);

Again, assuming that we are not using a greater then 4 byte ptr*, since otherwise it would not increment... But personally I think that this is not required.

Cheers,
Paul

Attachment: PGP.sig
Description: This is a digitally signed message part