gcc wont compile code with ?: operator
John V. Pope
jpope_rhn at popes.net
Mon Feb 16 16:32:51 UTC 2004
I was coding a simple C program and I found a bug in the gcc compiler.
The following code is a simple demonstration of the bug and should compile without errors:
--X-snip-X--
#include <stdio.h>
main()
{
char a[80];
char b[80];
int x;
for(x = 0; x < 80; x++)
{
/*
This works just fine
*/
if(isprint(a[x]))
b[x] = a[x];
else
b[x] = '.';
/*
?: operator won't compile
gcc version 3.3.2 20031022 (Red Hat Linux 3.3.2-1)
error: invalid lvalue in assignment
*/
isprint(a[x]) ? b[x] = a[x]: b[x] = '.';
}
}
--X-snip-X--
As my sample shows, the compiler can't handle the ?: operator.
I have used the ?: operator many times over the past decade and expect it to work under gcc.
Does anyone have a clue what's going on?
Thanks,
John V. Pope
More information about the fedora-list
mailing list