From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 6AB0CBB9A for ; Tue, 15 Nov 2005 14:33:20 +0100 (CET) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id jAFDXIrm002749 for ; Tue, 15 Nov 2005 14:33:19 +0100 Received: from rosella (ppp7-104.lns1.syd7.internode.on.net [59.167.7.104]) by smtp1.adl2.internode.on.net (8.12.9/8.12.6) with ESMTP id jAFDX3uI005697; Wed, 16 Nov 2005 00:03:05 +1030 (CST) (envelope-from skaller@users.sourceforge.net) Subject: Re: [Caml-list] ocamlc -output-obj problems From: skaller To: Alessandro Baretta Cc: Jonathan Roewen , caml-list@yquem.inria.fr In-Reply-To: <4379DC20.8040704@barettadeit.com> References: <1132028623.11813.99.camel@rosella> <4379DC20.8040704@barettadeit.com> Content-Type: text/plain; charset=utf-8 Date: Wed, 16 Nov 2005 00:33:03 +1100 Message-Id: <1132061583.9002.39.camel@rosella> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 8bit X-Miltered: at nez-perce with ID 4379E39E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 ocamlc:01 -output-obj:01 baretta:01 char:01 argv:01 char:01 argv:01 pointer:01 pointer:01 pointers:01 gcc:01 wrote:01 wrote:01 sourceforge:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 On Tue, 2005-11-15 at 14:01 +0100, Alessandro Baretta wrote: > Jonathan Roewen wrote: > > It's all my fault. It's always all my fault ;D > > > > char **argv = ... => char *argv[] = ... > > Please excuse my stupidity: what's the difference? The first case says argv is a pointer to a pointer. The second says it is an array of pointers. When you pass an argument of the second type to a function, it *decays* to the first type: there is no difference accessing the two. But there is a HUGE difference in the data structure created by a declaration -- the first reserves exactly one word of storage. The second reserves an actual array. Watch: This compiles: char * a[] = {"A","B"}; char ** b = a; This does NOT compile: char * a[] = {"A","B"}; char ** b = {"A","B"}; a.c:2: warning: initialization from incompatible pointer type a.c:2: warning: excess elements in scalar initializer a.c:2: warning: (near initialization for ‘b’) Note also: ++a is illegal, a is a constant. You cannot increment an array. But ++b is allowed, it is merely a pointer to the first element of the array. And now notice Jonathan wrote: > char **argv = ... => char *argv[] = ... with an = in there. Looks like his gcc is broken :) -- John Skaller Felix, successor to C++: http://felix.sf.net