[net.lang.c] Non-reentrant code generated by C compiler

ado@elsie.UUCP (08/22/84)

Here's a lint trap for nonportable structure returns.
It's an addition to "/usr/src/cmd/lint/lint.c"
(or whatever the equivalent is on your system).

	ed - /usr/src/cmd/lint/lint.c
	/o = p->in.op/a
	#ifndef OLDVERSION
		case NAME:
			if (pflag && p->in.type == (FTN | STRTY))
				werror("nonportable return of structure");
			break;
	#endif
	.
	w
	q
--
	...decvax!seismo!umcp-cs!elsie!ado	(301) 496-5688
	(DEC, VAX and Elsie are Digital Equipment Corp. and Borden's trademarks)

gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (08/22/84)

How about changing the lint message from "nonportable return of structure"
to "structure return is nonreentrant".  There is nothing nonportable about
struct-valued functions.

ado@elsie.UUCP (08/23/84)

> How about changing the lint message from "nonportable return of structure"
> to "structure return is nonreentrant".  There is nothing nonportable about
> struct-valued functions.

Actually, with all the muttering in this group of late on how to redo struct-
valued returns, returning a structure probably IS nonportable--sometimes it
will be reentrant, sometimes not.

And, of course, return of structures was absent before the advent of Version 7--
so struct-valued functions are not portable to Version 6 and its clones.
--
	...decvax!seismo!umcp-cs!elsie!ado	(301) 496-5688
	(DEC, VAX and Elsie are Digital Equipment Corp. and Borden's trademarks)

gwyn@BRL-VLD.ARPA@sri-unix.UUCP (08/24/84)

From:      Doug Gwyn (VLD/VMB) <gwyn@BRL-VLD.ARPA>

If you start worrying about staying compatible with 6th Edition C,
you have REAL portability problems.  6th Edition UNIX did not have
the current stdio, or any of the portability features put into C
for the 7th Edition (typecasts, for example).  It is really asking
too much to insist on 6th-Edition compatible C code.

henry@utzoo.UUCP (Henry Spencer) (08/26/84)

> Actually, with all the muttering in this group of late on how to redo struct-
> valued returns, returning a structure probably IS nonportable--sometimes it
> will be reentrant, sometimes not.

There's nothing unportable about structure returns if your code doesn't
need reentrancy, which is true of 95% of all C programs at least.

> And, of course, return of structures was absent before the advent of Version 7--
> so struct-valued functions are not portable to Version 6 and its clones.

There were a great many other things absent before V7; very few modern
C programs will compile successfully on a V6 C compiler.  For example, both
"long" and "typedef" arrived after V6 (although some "6.5" compilers, like
the Phototypesetter compiler, had them).  Portability to a true V6 compiler
is prohibitively difficult, and probably not worthwhile.  V7 is the de facto
standard against which C compilers have been measured for some time.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry

ado@elsie.UUCP (Arthur David Olson) (09/15/84)

Let's try for a lint trap that everyone can agree on.
Remove the change given in <1154@elsie.UUCP>, then install this one:

	ed /usr/src/cmd/lint/lint.c
	/cfp =/a
	#ifndef OLDVERSION
		if (pflag && cfp->stype == (FTN | STRTY)) {
			werror("struct return reentrancy varies among systems");
			werror("pre-Version-7 systems don't do struct returns");
		}
	#endif
	.
	w
	q

Perhaps the long run thing to do is change "lint" so that you can ask
for different degrees of portability checking.  "lint -P V.2", "lint -P V",
"lint -P III", "lint -P 7", "lint -P 6", "lint -P 5"...?

Another thing we can is to call software "V7-portable" rather than "portable"
when the former label is more accurate.

And by way of explanation. . .I was working on a PDP 11/40 when Version 7 was
released.  And was horrified to learn that Bell Labs was abandoning support
of 11/40's (UNIX had grown too large to fit in their address space).  So for
years after other folks had converted to Version 7, I worked in a Version 6
environment.  Whence my (over-?)sensitivity to the plight of Version 6 folk.

Finally--

> There's nothing unportable about structure returns if your code doesn't
> need reentrancy, which is true of 95% of all C programs at least.

Clearly I believe it's worth trying to catch the 5%.  Then again, I'm
risk-averse:  I'd be loathe to take an airline flight if I had a 95% chance of
surviving.
--
UNIX is an AT&T Bell Laboratories trademark.
--
	...decvax!seismo!umcp-cs!elsie!ado	(301) 496-5688
	(DEC, VAX and Elsie are Digital Equipment Corp. and Borden's trademarks)