This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- InstallShield
- :
- InstallShield Forum
- :
- Handling of Boolean Logic Operators [bug?]
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 22, 2008
02:18 PM
Handling of Boolean Logic Operators [bug?]
Is this a boolean logic bug? Or am I going crazy?
Summary:
The operators || && appear to evaluate EVERY function, regardless of whether they needed to be evaluated or not. This is in stark contrast to nearly every other language.
Here is the code that I've created to come to this conclusion, please try it out and let me know what results you get.
In EVERY case, each function is evaluated and then the result from each function is used to determine whether or not the condition is true.
Please tell me I am doing something wrong.
Summary:
The operators || && appear to evaluate EVERY function, regardless of whether they needed to be evaluated or not. This is in stark contrast to nearly every other language.
Here is the code that I've created to come to this conclusion, please try it out and let me know what results you get.
#ifdef WTF_BUG
prototype A(BOOL);
prototype B(BOOL);
prototype C(BOOL);
function A(ret)
begin
MessageBox("A", INFORMATION);
return ret;
end;
function B(ret)
begin
MessageBox("B", INFORMATION);
return ret;
end;
function C(ret)
begin
MessageBox("C", INFORMATION);
return ret;
end;
#endif
function OnBegin()
begin
// This first part is meant to determine whether boolean logic is sane at all in the first place, and also that the functions A B C are operating as expected (input->output)
#ifdef WTF_BUG
if A(TRUE) == TRUE then
MessageBox("true is true", INFORMATION);
endif;
if !A(TRUE) == FALSE then
MessageBox("!true is false", INFORMATION);
endif;
if A(FALSE) == FALSE then
MessageBox("false is false", INFORMATION);
endif;
if !A(FALSE) == TRUE then
MessageBox("!false is true", INFORMATION);
endif;
// this section is meant to test the logic operators
if A(TRUE) == TRUE || B(FALSE) == TRUE || C(TRUE) == TRUE then
MessageBox("should Only see A", INFORMATION);
endif;
if (A(FALSE) == TRUE || B(TRUE) == TRUE) || C(FALSE) == TRUE then
MessageBox("should only see A B", INFORMATION);
endif;
if A(FALSE) == TRUE && B(TRUE) == TRUE && C(TRUE) == TRUE then
MessageBox("Should not see this message", INFORMATION);
else
MessageBox("Should only see A", INFORMATION);
endif;
if A(TRUE) == TRUE && B(FALSE) == TRUE && C(TRUE) == TRUE then
MessageBox("Should not see this message", INFORMATION);
else
MessageBox("Should only see A B", INFORMATION);
endif;
if A(FALSE) == TRUE || B(FALSE) == TRUE || C(FALSE) == TRUE then
MessageBox("Should not see this message", INFORMATION);
else
MessageBox("Should see A B C", INFORMATION);
endif;
if A(FALSE) == TRUE && B(FALSE) == TRUE && C(FALSE) == TRUE then
MessageBox("Should not see this message", INFORMATION);
else
MessageBox("Should only see A", INFORMATION);
endif;
abort;
#endif
In EVERY case, each function is evaluated and then the result from each function is used to determine whether or not the condition is true.
Please tell me I am doing something wrong.
(3) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 22, 2008
02:22 PM
It is odd, compared to C/C++, that boolean operators don't short-circuit in InstallScript, but that is how they're documented to work; please see the caution in the help topic "Logical Operators (&&, ||, !)".
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 22, 2008
02:37 PM
Thanks Robert! It's a feature, ha.
Oddly enough that is the very help page that I had open when I went to look for the document you suggested. Apparently my eyes avoid the giant bold emphasis caution block.
It is definitely documented, but could they really do more to make it stand out? 😄
Oddly enough that is the very help page that I had open when I went to look for the document you suggested. Apparently my eyes avoid the giant bold emphasis caution block.
It is definitely documented, but could they really do more to make it stand out? 😄
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Aug 22, 2008
05:57 PM
Maybe we can get the caution paragraph to blink or something, ha ha?