Hi the list,
I know for having read it somewhere that, as does gcc, GPC stops evaluating as soon as it knows what is the result. For example, evaluating for A and B, with A set to 0, it does not evaluate B for it knows it does not worth doing it.
I don't know if this is due to the fact that, at a certain scale, GPC is mixed up with gcc, and here is my question:
Is it a particularity of gcc (injected in GPC) or is it something true for all compilers. At least, can one code with this feature in the back of the mind without fear of borland unportability.
One may object that it does not change anything but efficiency. I have conversely some code that will work if only the first part is evaluated but will bug if the second is (that is quite curious. Don't worry. It works with GPC, will it too with borland?)
Cheers.
Hi!
According to FPL:
I know for having read it somewhere that, as does gcc, GPC stops evaluating as soon as it knows what is the result. [...] Is it a particularity of gcc (injected in GPC) or is it something true for all compilers. At least, can one code with this feature in the back of the mind without fear of borland unportability.
This is a Borland special, integrated into GPC for compatibility. In both GPC and BP it can be switched on and off.
One may object that it does not change anything but efficiency. I have conversely some code that will work if only the first part is evaluated but will bug if the second is (that is quite curious. Don't worry. It works with GPC, will it too with borland?)
It will work with Borland Pascal if you switch "Boolean complete evaluation" off, either through a menu option or through the "(*$B-*)" directive (which is also understood by GPC).
The ISO Standard, OTOH, says that you cannot rely on a certain order of evaluation of the operands or whether they are evaluated at all. Thus, GPC's default behaviour is compliant with ISO. However, there seems to be a de-facto-standard among some ISO Pascal compilers to do a complete evaluation, thus GPC switches to this default behaviour in ISO Pascal mode.
Greetings,
Peter