gcc wont compile code with ?: operator

Steve Wampler swampler at noao.edu
Mon Feb 16 16:50:48 UTC 2004


On Mon, 2004-02-16 at 09:46, John V. Pope wrote:
> On Mon, Feb 16, 2004 at 09:35:46AM -0700, Steve Wampler wrote:

> > Check the precedence rules between = and ?:.

> 
> Adding parens, like so
> 
> isprint(a[x]) ? (b[x] = a[x]) : (b[x] = '.');
> 
> does allow it to compile but this was never needed before as far as I can recall.

Hmmm, should have been - those precedence rules have been
around from the early days of C (certainly as long as ?: has
existed).  GCC would have been broken before if you were
able to get your original statement working.  As someone
else pointed out, it's probably cleaner to replace the
above with:

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

which is how ?: is 'normally' used.
-- 
Steve Wampler -- swampler at noao.edu
The gods that smiled on your birth are now laughing out loud.





More information about the users mailing list