Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!mit-eddie!bu-cs!bucsb.bu.edu!madd From: madd@bucsb.bu.edu.UUCP Newsgroups: comp.unix.wizards Subject: Re: Possible Bug in BSD Message-ID: <784@bucsb.bu.edu.UUCP> Date: Thu, 26-Feb-87 22:22:46 EST Article-I.D.: bucsb.784 Posted: Thu Feb 26 22:22:46 1987 Date-Received: Sun, 1-Mar-87 08:52:33 EST References: <4685@brl-adm.ARPA> Reply-To: madd@bucsb.bu.edu.UUCP (Jim "Jack" Frost) Organization: ODO (Organization for the Disorganization of Organization) Lines: 57 In article <4685@brl-adm.ARPA> sefunix%sefe.decnet@nwc-143b.arpa (SEFE::SEFUNIX) writes: >We have run into a little problem on both Ultrix-32m (DEC microvax) >and MT. Xinu 4.3BSD on a DEC microvax. Can someone try this program >on their system and see if they also get a segmentation violation >on the fopen of argv[1]. > >And if so, why? > >#include > >struct abc >{ > short Red; > short Green; > short Blue; > short Alpha; >}; > >main (argc, argv) >int argc; vvvvvvvvvvvv >char **argv; ^^^^^^^^^^^^ >{ > FILE *f1, *fopen(); > > struct abc point[151][451]; > > if (argc !=2) > { > puts("\n Usage: InputFileName \n"); > exit(1); > } > > if((f1 = fopen(argv[1], "r")) == NULL ) > { > printf("I can't open %s\n", argv[1]); > exit(1); > } > > fclose(f1); >} You really shouldn't have declared char **argv if you want to treat argv as an array. Instead, change that declaration to *argv[], or reference it as a pointer structure (eg *(argv+1)==argv[1]). I suspect that C doesn't treat arrays of pointers exactly as it treats pointers to pointers, but I'm not really that sharp on the subject. I just treat them as if they were two completely different types of variables, and this keeps things simple. Some C compilers will give you "type mismatch" errors when you define a pointer value and then reference it as an array. The 4.3BSD compiler on our vax 750 did not, however. jim frost madd@bucsf.bu.edu ..!harvard!bu-cs!bucsf!madd