short-circuit logic in PL1 compiler, or lack thereof 
Author Message
 short-circuit logic in PL1 compiler, or lack thereof


> I recall reading once that the it is dangerous to assume the PL1 compiler will
> perform short-circuit logic.  Is this real danger?  For example:

>     declare p pointer;
>     declare 1 some_other_structure
>         2 some_field bin(15);
>     declare 1 some_structure like some_other_structure based (p);

> Then ... code like the following is dangerous or susceptible to error/crash?

>     if ((p ^= null) & (some_structure.some_field = 15)) then

> That is ... making an assumption that the fact that the first expression will
> evaluate to false if the pointer is null, and the compiler will not run the
> code in the second expression which is based on that pointer.

> Can anyone explain the actual workings of the compiler in regards to this?  Is
> this a problem with non-optimized code perhaps?  Or perhaps optimized code?

There is no requirement that only p ^= null be evaluated.

Nor is there any requirement that p ^= null be evaluated first, before
some_structure.some_field = 15.

The correct way to write it is:

if p ^= null then
  if ...

Sat, 28 Dec 2002 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. short-circuit logic in PL/I compiler, or lack thereof

2. Which compiler does not short circuit by default?

3. Which compiler does not short circuit by default?

4. Number syntax, or lack thereof

5. Tree comprehension (or the lack thereof)

6. Fivewin support in OZ (or lack thereof)

7. DbC, lack of thereof, and the Linux kernel

8. Ethics (or lack thereof)

9. PYTHONDOCS, or lack thereof...

10. Tk performance (lack thereof)

11. Const correctness (and the lack thereof)

12. long = short*short ; (short,short) = long/short


Powered by phpBB® Forum Software