Re: gcc wont compile code with ?: operator

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

 



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@xxxxxxxx
The gods that smiled on your birth are now laughing out loud.




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

  Powered by Linux