From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id GAA25961; Mon, 4 Jun 2001 06:49:40 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id GAA26305 for ; Mon, 4 Jun 2001 06:49:39 +0200 (MET DST) Received: from verdot.inria.fr (verdot.inria.fr [128.93.11.7]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f544naD18915; Mon, 4 Jun 2001 06:49:37 +0200 (MET DST) Received: (from ddr@localhost) by verdot.inria.fr (8.9.3/8.9.3) id GAA23294; Mon, 4 Jun 2001 06:49:36 +0200 Date: Mon, 4 Jun 2001 06:49:36 +0200 From: Daniel de Rauglaudre To: Harry Chomsky Cc: Caml list Subject: Re: [Caml-list] Win32 API Message-ID: <20010604064936.A23225@verdot.inria.fr> References: <00c301c0ea11$17a38570$22f65140@w2kpro> <20010601001301.A11836@verdot.inria.fr> <00ff01c0ea25$68d716f0$22f65140@w2kpro> <20010601134802.G15012@verdot.inria.fr> <008101c0ecab$148c84d0$22f65140@w2kpro> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0us In-Reply-To: <008101c0ecab$148c84d0$22f65140@w2kpro>; from harry@chomsky.net on Sun, Jun 03, 2001 at 09:01:49PM -0700 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, On Sun, Jun 03, 2001 at 09:01:49PM -0700, Harry Chomsky wrote: > Now, what happens in the following situation? > some_function(alloc_something(), alloc_something_else()); It is unsafe. In C, you cannot call a function of two parameters if one can modify the evaluation of the other: some_function(i, i++); some_function(a[i], i++); In these examples, for the first parameter, you don't know which i is concerned: the initial value of i or its ending value i + 1. > CAMLlocal1(v); > v = alloc_something(); > some_function(v, alloc_something_else()); The rules in C are clear: the evaluation order of the parameters is unspecified. All these calls are then illegal. You even cannot hope that a CAMLlocal1(v) would save the value of v pushed one the stack since in C, all parameters are transmitted by value. Therefore, you can fix the value of v as many times you want by the CAMLlocal feature, the pushed value will not change. Your second example would work with a C compiler evaluating the last parameters before the first ones. > So the only safe solution is to go all the way: > > CAMLlocal2(v1, v2); > v1 = alloc_something(); > v2 = alloc_something_else(); > some_function(v1, v2); Right. -- Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr