From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: char **argv vs. char *argv[] Date: Thu, 12 Jun 1997 08:51:13 -0700 Organization: Alcyone Systems Lines: 40 Message-ID: <33A01AF1.18F2A173@alcyone.com> References: <5ndap9$mgd AT freenet-news DOT carleton DOT ca> <01bc74bd$7df85940$e38033cf AT pentium> <5ngpcv$a6v$3 AT sun1000 DOT pwr DOT wroc DOT pl> NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Springman wrote: > The *argv[] is used more probably because it is safer. Why? > A basic example: > void func1 (int *p); > void func2 (int p[]); > Both func1 and func2 accept pointers to ints as arguments. But they are > not exactly the same. The func2 takes a pointer that is constant, i.e. > you'll get warnings when you try to modify its value. No, you won't. The ANSI C specification specifically states that an array argument decays to a pointer argument. No implicit consts are introduced by the compiler. As such, the following function is perfectly legal: void f(int a[]) { static int x; a = &x; } The reason is because arrays are automatically treated as pointers in function arguments, so this function is in fact treated as void f(int *a) /* ... */ and as such using the argument as an lvalue is perfectly legal. (Perhaps not very useful, though, because its value is only being changed within the function.) Your statement is tantamount to stating that the int a[] argument would be silently treated as a int *const, which is not correct. -- Erik Max Francis, &tSftDotIotE / email / max AT alcyone DOT com Alcyone Systems / web / http://www.alcyone.com/max/ San Jose, California, United States / icbm / 37 20 07 N 121 53 38 W \ "Covenants without the sword / are but words." / Camden