MAP REWRITE patch 0.9

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Tron
OpenTTD Developer
OpenTTD Developer
Posts: 57
Joined: 13 Dec 2004 23:15

Post by Tron »

prissi wrote: return _m[t].bar << 3 || _m[t].foo;

is equal to

return (_m[t].foo!=0);
err, no
due to the accidental use of the logical or which has only 0 and not zero (most compiler reutrn 1, few -1) here.
and all compilers generating -1 for true boolean expressions are broken, because the C standard mandates that the result of a logical expression is either 0 for false or 1 for true.
On the other hand all input values unequal to 0 are interpreted as true.
Tron
OpenTTD Developer
OpenTTD Developer
Posts: 57
Joined: 13 Dec 2004 23:15

Post by Tron »

Korenn wrote:
DaleStan wrote:I was not talking about mkxx's concept either. (Well, I was other places, but not there.)

I was talking about the "return _m[t].bar << 3 || _m[t].foo;" statement.

It is valid, but it has no logical meaning.
if you really want to nickpick like that, yes it does have logical meaning. shifting by 3 bits can mean you shift out 3 bits.
so then it would be equivalent to

return _m[t].bar & 0x1F || _m[t].foo

if _m[t].bar is an 8 bit variable.
Still horrible style, but it definitely has logical meaning. So go away and come back when you've learned some manners.
no
if .bar is a char variable it gets promoted to int before evaluating the expression.
Therefore _m[t].bar << 3 is not equal to _m[t].bar & 0x1F for a logical test.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 20 guests