POV-Ray : Newsgroups : povray.programming : HF height: bug report : HF height: bug report Server Time
6 Oct 2024 11:10:50 EDT (-0400)
  HF height: bug report  
From: Vadim Sytnikov
Date: 4 Aug 2001 20:38:54
Message: <3b6c959e@news.povray.org>
The following is an excerpt from express.c
(MegaPov 0.6a, lines 505 and below):

  if( hfield->Type & HFIELD_OBJECT != HFIELD_OBJECT )
    Error( "Cannot find height of non-height-field.\n" );
  if( ( Val < 0 ) || ( Val2 < 0 ) ||
    ( Val > 1 ) || ( Val2 > 1 ) )
      Error( "Height-field index out of bounds [0 1].\n" );

Since the precedence of 'not equal' is higher than that
of 'bitwise and', the very first line really means

  if( hfield->Type & 0 )

and thus the error message never appears. In fact,
optimizing compilers eliminate entire statement. I
quoted a little bit more than necessary just to illustrate
(and rant :-) how... unwise people use parentheses.

BTW (to those who are interested): this strange
precedence rule goes deep into the history of C...
From the very beginning, there were no such things
as 'logical and' and 'logical or' (that is, '&&' and '||'),
the only 'and' and 'or' operators were '&' and 'I',
respectively, serving as either logical or bitwise
based upon context ("truth-value-context"). When
their "pure logical" counterparts were introduced,
K&R were forced to stick with their current
precedence to maintain compatibility with existing
code.That's that.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.