home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!daffodil!wyvern!alpha
- From: alpha@wyvern.twuug.com (Joe Wright)
- Subject: Re: Computer terms, etc
- Message-ID: <1992Aug17.032216.5689@wyvern.twuug.com>
- Organization: Box 68621, Virginia Beach, 23455
- X-Newsreader: Tin 1.1 PL4
- References: <19590@fritz.filenet.com>
- Date: Mon, 17 Aug 1992 03:22:16 GMT
- Lines: 60
-
- scotth@felix.filenet.com (Scott Hopson) writes:
- : In article <1992Aug13.192456.19127@Synopsys.Com> jerry@synopsys.com (Jerry Huth) writes:
- : >
- : >Scott Hopson (scotth@filenet.com) says:
- : >>> > and what is the diff. between *foo[] and **foo?
- : >>> *foo[] is a pointer to an array
- : >
- : >No, it's an array of pointers, because [] has higher precedence than *.
- :
- : Sorry, it was 2:00 AM when I wrote that, I guess I forgot to put
- : "of pointers" on the end.
- :
- :
- : *foo[] is a pointer to an array [of pointers]
- :
- :
- : thanks for the correction.
- :
- : --
- : Scott Hopson (scotth@filenet.com)
-
- Sorry if I'm beating a dead horse but...
-
- char *foo[] = {"abc", "def"};
- char **bar;
-
- foo is an array of pointer to char. bar is a pointer to a pointer to char.
-
- bar = foo;
-
- This works only because the compiler dereferences foo as &foo[0] to create
- a pointer value. This does not make foo a pointer (although bar is).
-
- The only place that *a[] and **a can be used interchangeably is in the
- declaration of formal parameters in functions. This because parameters
- are passed by value to functions and a would be dereferenced to &a[0],
- a pointer and placed in an automatic variable for the function.
-
- fun(foo);
-
- fun(a) char *a[]; {}
-
- The value passed to fun() is &foo[0] and is placed in a as foo is called.
- For this reason **a is legal and would give the char pointed to by the
- pointer in a. To avoid confusion,
-
- fun(a) char **a; {}
-
- is much preferred. I'm not confused. Really I'm not.
-
- main(argc, argv) char **argv; {}
-
- is preferred for the same reason. *argv[] is really an array of pointers
- and ++argv; would have no meaning. Actually argv is passed to main as
- &argv[0] and placed in a variable on the stack. Hence the second
- declaration is clearer and more correct. Now ++argv clearly increments
- the pointer variable on the stack, not the array. Clear?
-
- --
- Joe Wright alpha@wyvern.twuug.com
-