delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/07/17:50:42

Message-Id: <1.5.4.32.19970807214727.0069a31c@dce03.ipt.br>
Mime-Version: 1.0
Date: Thu, 07 Aug 1997 18:47:27 -0300
To: Charles Krug <charles AT pentek DOT com>, djgpp AT delorie DOT com
From: Cesar Scarpini Rabak <csrabak AT dce03 DOT ipt DOT br>
Subject: Re: [Q] expression evaluation order

At 09:10 07/08/97 +0100, Charles Krug wrote:
>No.

Wrong!

>
>I think that ANSI tries to demand left-to-right evalutaion of &&.  But
>not all compilers do this correctly.  To guarantee left-to-right
>evaluation, you need:

ANSI does not _try_, it demands!, if some compiler does not conform is
faulty (not 'buggy', which you could live with).

In fact, this is a behaviour constructed in the design of the language:

K&r 2nd ed. pg. 41 last par.: "... Expressions connected by && or || are
evaluated left to  right, and evaluation stops as soon as the truth or
falsehood of the result is known. Most C programs rely on these properties."

This is basic in C!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cesar Scarpini Rabak                      E-mail: csrabak AT ipt DOT br
DME/ASC                                   Phone: 55-11-268-3522 Ext.350
IPT - Instituto de Pesquisas Tecnologicas Fax:   55-11-268-5996
Av. Prof. Almeida Prado, 532.  Sao Paulo - SP 05508-901 BRAZIL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019