lad@eplrx7.UUCP (Lawrence Dziegielewski) (08/27/87)
Consider the following program:
------------------------------------
#include <stdio.h>
char fstat;
main()
{
FILE *fp;
fp = fopen("testfile", "w");
fprintf(fp, "xxxxx");
fclose(fp);
}
------------------------------------
On our Sun Unix 3.4 and DEC Ultrix 2.0,
it results in either a "bus error" or "segmentation fault",
which occurs deep within the fprintf().
On Unix System V and MS-DOS Lattice C,
it executes without problem, as it should.
The problem is that the character variable 'fstat',
declared externally, conflicts with the fstat() system call.
If this is indeed a problem for Berkley, then the compiler
ought flag the external declaration as a redeclaration, but
this is not the case, it compiles without incident. Also note
that fstat is declared char, fstat() is int.
This feature is not limited to fstat() - it fails just as well
for other system calls. (But not on System V or Lattice C).
--
Lawrence A. Dziegielewski | E.I. Dupont Co.
{uunet!dgis!psuvax1}!eplrx7!lad | Engineering Physics Lab
Cash-We-Serve 76127,104 | Wilmington, Delaware 19891
MABELL: (302) 695-1311 | Mail Stop: E357-318
mouse@mcgill-vision.UUCP (09/22/87)
In article <462@eplrx7.UUCP>, lad@eplrx7.UUCP (Lawrence Dziegielewski) writes: > [re conflict between a variable "fstat" and the syscall] > [program with fstat variable dies: stdio uses fstat() the syscall] You are using a reserved identifier (fstat) in a way which does not match what it is reserved to mean. Sometimes you will get away with this (eg, same program, change "fstat" to "mknod" and it will probably work), sometimes you won't. (By a "reserved" identifier I mean one which has a meaning assigned by the system, not reserved in the sense of a language keyword like "sizeof" or "while".) > If this is indeed a problem for Berkley, then the compiler ought flag > the external declaration as a redeclaration, Why? You haven't redeclared fstat. The *loader* should warn, but currently can't because all it sees in stdio is "reference to external undefined" which it can't check against "definition of external data" - it doesn't know it should be "...external text". If the compiler and loader cooperated, the loader could complain about satisfying a text segment reference with a data segment symbol. der Mouse (mouse@mcgill-vision.uucp)