Browse thread
[Caml-list] ocamlc -output-obj problems
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-11-15 (13:33) |
From: | skaller <skaller@u...> |
Subject: | Re: [Caml-list] ocamlc -output-obj problems |
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