>On Sun, 19 Aug 2007 22:52:12 -0000,
wrote:
[given: a typedef-alias named "edge", a #define constant for
MAX_GRAPH, and]
>>int print_structure(edge *graph[MAX_GRAPH][MAX_GRAPH]){
In article <>
Barry Schwarz <> wrote:
>This function is expecting an array of pointer to struct.
Well, the type of the argument named "graph" is -- before the
adjustment you describe in a moment -- "array MAX_GRAPH of array
MAX_GRAPH of pointer to what-edge-is-short-for". So, array of
arrays, each element of the nested array being a pointer to struct
(since edge is short for a struct type).
>Due the fact that an array expression in this context is converted
>to a pointer to the first element, the actual type the function is
>expecting is
> edge (*)(*[MAX_GRAPH])
Right -- a formal parameter whose type *appears* to be "array N of
T" (for some integer N, or even an omitted integer, and any valid
type T) really gets declared as having type "pointer to T", replacing
the first (and only the first!) "array of" part of the expanded
English version with "pointer to" -- except that the C spelling of
the type "pointer to array MAX_GRAPH of pointer to
whatever-edge-is-short-for" is actually:
edge *(*)[MAX_GRAPH]
The parentheses "look weird" because we lack the identifier that
would go in there. If this were an actual declaration instead of
just a type-name, we would have:
edge *(*ptr)[MAX_GRAPH];
Here, the need for the parentheses is clearer (if not exactly
"clear"!) since we need to bind the inner (second) "*" to "ptr",
then bind the "[MAX_GRAPH]" to that, and then bind the outer (first)
"*" to that, and finally bind the typedef-alias "edge" to that.
Without parentheses, the "[MAX_GRAPH]" would bind to "ptr" first,
then the second "*" would bind to that, and so on.
To turn a C declaration into a type-name, one simply removes the
identifier that was being declared. In this case, it results in
parentheses around the second "*".
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.