From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p7GGYbdq026377 for ; Tue, 16 Aug 2011 18:34:37 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AosBAN2aSk7RVaE2kGdsb2JhbABBqDYIFAEBAQEJCQ0HFAQhgUABAQEBAxICLAEbHAIDDAYFCw0JFg8JAwIBAgEREQEFARwHDAgCHodQm0UKjDeCVYU2O4htAgMGhkIEh1mLOYUMgSiGJTyDYw X-IronPort-AV: E=Sophos;i="4.68,234,1312149600"; d="scan'208";a="105606051" Received: from mail-fx0-f54.google.com ([209.85.161.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 16 Aug 2011 18:34:34 +0200 Received: by fxe4 with SMTP id 4so196655fxe.27 for ; Tue, 16 Aug 2011 09:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type :content-transfer-encoding; bh=q9vcLEWJjkGUQf4QZILkbzE7eGvDN4ouofP0DWlHpC4=; b=uipBKj0x+mdoTQVWw3d6w05vWpTv00P2DEHFdqKUbfsSTT5r0tM1StvscW6JehVDZL YfKrlWU8xGXqX5TEWQylmUXOseyomE8PO9u9Gea8uc+QBsP6y/gtHLJPD0ATlphn4Rf8 Bi0Ib/X/QMIad8ANpY6GfdgUp0M3aQNFnnBss= Received: by 10.223.58.75 with SMTP id f11mr7454277fah.70.1313512474423; Tue, 16 Aug 2011 09:34:34 -0700 (PDT) Received: from [192.168.1.101] ([79.114.94.185]) by mx.google.com with ESMTPS id 16sm146817faw.18.2011.08.16.09.34.32 (version=SSLv3 cipher=OTHER); Tue, 16 Aug 2011 09:34:32 -0700 (PDT) Message-ID: <4E4A9C17.7060605@gmail.com> Date: Tue, 16 Aug 2011 19:34:31 +0300 From: =?ISO-8859-1?Q?T=F6r=F6k_Edwin?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110626 Icedove/3.1.11 MIME-Version: 1.0 To: caml-list@inria.fr, rich@annexia.org References: <20110816152550.GA21081@annexia.org> <20110816155137.GA18365@ccellier.rd.securactive.lan> <20110816161042.GA31932@annexia.org> <20110816162205.GC31932@annexia.org> <20110816162719.GD31932@annexia.org> In-Reply-To: <20110816162719.GD31932@annexia.org> X-Enigmail-Version: 1.1.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Interfacing with C: bad practice On 08/16/2011 07:27 PM, Richard W.M. Jones wrote: > Grrr now _my_ program has a bug. > > ---------------------------------------------------------------------- > #include > #include > > void f (int a, int b); > int g (void); > int *global = NULL; > > int > main (void) > { > int x = 1; > global = &x; > f (g (), x); > > exit (0); > } > > void > f (int a, int b) > { > printf ("a = %d, b = %d\n", a, b); > } > > int > g (void) > { > if (global) { > (*global)++; > return *global; > } > else > return 42; > } > ---------------------------------------------------------------------- > > This program doesn't show undefined behaviour. Undefined behaviour doesn't mean it must show different results with -O2, it *might* if the compiler decides to do some optimization. But isn't this 'f(g(), x)' issue the same as the classic example of undefined behaviour with f(++i, ++i)? Best regards, --Edwin