In message <20040331101834.GA21652_at_dyn-099164.nbw.tue.nl>, Rene Ladan writes: > >--rwEMma7ioTxnRzrJ >Content-Type: text/plain; charset=us-ascii >Content-Disposition: inline > >Hi, > >I'm getting runtime errors when executing the following program and >declaring one of the arrays: > >---------------- > >#include <stdio.h> > >int main(void) { >/* int a[4] = { 0, 1, 2, 3 }; enable this line to get a buserror */ > int *i; >/* int b[4] = { 0, 1, 2, 3 }; enable this line to get a segfault */ > for (*i = 0; *i < 4; (*i)++) > printf("%p %i\n", i, *i); > return(0); > } You have allocated no storage backing for *i, so your for loop writes the integers 0...3 to a random place in memory. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk_at_FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence.Received on Wed Mar 31 2004 - 00:20:41 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:49 UTC