Older Newer
Tue, 31 Dec 2019 16:08:26 . . . . SyneRyder [fix formatting]


Changes by last author:

Added:
= true =

== Description ==

true is a Boolean constant representing a logical state of "truth". In FilterMeister, any non-zero numeric value, any non-NUL character constant, or any non-null pointer represents a state of "truth", but the numeric value 1 is reserved as the canonical value for "truth". Thus, the Boolean constant true has a numeric value of 1 when evaluated in a numeric context.

Note, however, that any non-zero value represents "truth", so the numeric constants 2, 0.003, 255, -1.0, and -88888 (and the string constant "Hello world" or the character constant 'Z') will also evaluate as true in a Boolean or logical context.

=== Caution ===

A common cause of mistakes in C or FM programming is to assume that any true value has the value 1 (or true). It is bad programming style, and a frequent cause of subtle errors, to code for example:

<code>

if (flag==true) break;

</code>

since this code will not break if the value of flag is 77, which also represents truth. Unless the programmer is specifically testing for the value 1, the preferred idiom would be:

<code>

if (flag) break;

</code>

which will break when flag contains any true value (i.e., any value but 0, ±0.0, '\0', or (NULL)?), and not just in the case that flag has the value 1.

Note that this caution does not apply to the Boolean constant false, since the canonical numeric value of false is 0. The only other representation of falsity is a NUL character or a null pointer, and the numeric value of these is always 0 in FM. Thus the following code fragment, while poor style, will always break correctly when flag has the value 0, ±0.0, false, '\0', or (NULL)?.

<code>

if (flag==false) break;

</code>

Nonetheless, the preferred coding style is:

<code>

if (!flag) break;

</code>

== Example ==

<code>

%ffp

OnFilterStart:{

bool flag = true;

Info("The integer value of true is %d", flag);

if (true) Info("The gostak distims the doshes.");

return false;

}

</code>

This snippet will display two message boxes with the messages:

<code>

The integer value of true is 1

The gostak distims the doshes.

</code>

== See Also ==

false, (NULL)?, Constants