delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/09/16:35:34

From: aho450s AT nic DOT smsu DOT edu (Tony O'Bryan)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: char **argv vs. char *argv[]
Date: Mon, 09 Jun 1997 15:17:14 GMT
Organization: Southwest Missouri State University
Lines: 42
Message-ID: <339c1dee.6520200@ursa.smsu.edu>
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: forseti.i17.smsu.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On 9 Jun 1997 11:28:31 GMT, dzierzaw AT elektryk DOT ie DOT pwr DOT wroc DOT pl (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.

Maybe I misunderstood what you said, but gcc reports no errors with this program
compiled with "gcc -Wall test.c":

int *Func1(int *Pointer)
  {
  Pointer += 5;
  Pointer[5] = 10;

  return Pointer;
  }

int *Func2(int Pointer[])
  {
  Pointer += 5;
  Pointer[5] = 10;

  return Pointer;
  }


int main(void)
  {
  int                            Variable[100];

  Func1(Variable);
  Func2(Variable);

  return 1;
  }

Note that both functions modify the pointer and place information into the
array.  Did I misunderstand what you were saying?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019