caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: Alessandro Baretta <a.baretta@barettadeit.com>
Cc: Jonathan Roewen <jonathan.roewen@gmail.com>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] ocamlc -output-obj problems
Date: Wed, 16 Nov 2005 00:33:03 +1100	[thread overview]
Message-ID: <1132061583.9002.39.camel@rosella> (raw)
In-Reply-To: <4379DC20.8040704@barettadeit.com>

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 <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


      reply	other threads:[~2005-11-15 13:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-15  3:52 Jonathan Roewen
2005-11-15  4:23 ` skaller
2005-11-15  5:03   ` Jonathan Roewen
     [not found]     ` <ad8cfe7e0511142131j4c53bae8td7f3af42e6cecf72@mail.gmail.com>
2005-11-15  5:32       ` Jonathan Roewen
2005-11-15  7:13         ` Jonathan Roewen
2005-11-15  8:14           ` Jonathan Roewen
2005-11-15 13:01             ` Alessandro Baretta
2005-11-15 13:33               ` skaller [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1132061583.9002.39.camel@rosella \
    --to=skaller@users.sourceforge.net \
    --cc=a.baretta@barettadeit.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=jonathan.roewen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).