drears@ardc.arpa (P) (03/20/86)
I work in a 4.2 BSD environment with brl "enhancements". What this means is we have access to system V commands and libraries but not to system V system calls. On one of the programs I was writing I had the following code: #include <stdio.h> . . . . writeda() { FILE *fopen(), *daction; if ((daction = fopen(file,"w"))== NULL){ fprintf(stderr,"ERROR: Could not create %s\n",file); perror(""); } /* Writes out actual file */ fprintf(daction," R & A\n"); . . . fclose(daction); } I compiled (maked) using the the -O flag (cc -O progname), when I ran the program that got to the first fprintf statement I got memory fault - core dump. After extensive checking of the program for bugs I gave up. I then ported it over to s System V machine and it worked with no problems. I then read the manual page on cc and read about the -7 option: -7 Compile using a 4.2BSD environment (a UNIX System V environment is the default.) AFter recompilng with the -O7 flags I got it to run and have had no problems since. The question I have is does the -7 option really do that much? What does it do? Could the error be me or the compiler option. I had never used -7 before. I have had no problems with prior programs. ..Dennis
gwyn@BRL.ARPA (VLD/VMB) (03/20/86)
The BRL UNIX System V emulation "cc -7" option merely substitutes the native Berkeley include directory and C library in place of the System V versions, while continuing to use the AT&T UNIX System V VAX C preprocessor, compiler, and code generator. There was not enough information in your sample code to be sure what the problem is, but I did notice the absence of any declaration for the variable `file'. My guess is that the fopen failed, since `file' was garbage, and then the fprintf to stderr died when it tried to print `file' as a string. Run a debugger (e.g. "adb" $C command) on the core image to see where it died. Incidentally, the BRL UNIX System V emulation C library includes emulations for the UNIX System V system calls. You should address BRL UNIX System V emulation questions to me directly <Gwyn@BRL.ARPA>, rather than to the news group. (I am answering this with copy to the news group just in case someone else is now curious about the answer.)