Re: gcc wont compile code with ?: operator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Feb 16, 2004, "John V. Pope" <jpope_rhn@xxxxxxxxx> wrote:

> The following code is a simple demonstration of the bug and should compile without errors:

As others have pointed out, the meaning this had with older versions
of GCC is not what you expect:

> 		isprint(a[x]) ? b[x] = a[x]: b[x] = '.';

this meant:

 		(isprint(a[x]) ? (b[x] = a[x]): b[x]) = '.';

i.e., it would assign '.' to b[x] regardless of the result.

That was because, if both branches of a ternary operator were lvalues,
GCC would, as an extension, consider the result of the expression to
be an lvalue as well.

Precisely because of coding errors like the one you mention, this
extension was removed, so now you get an error, as you should always
have.  And now you know the code is broken and has to be fixed.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Happy GNU Year!                     oliva@{lsd.ic.unicamp.br, gnu.org}
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist                Professional serial bug killer




[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux