[comp.lang.c] static functions broken in non-Unix compilers?

haugj@pigs.UUCP (John F. Haugh II) (05/16/88)

I have been informed that there is some trouble declaring functions to
be static in most of the non-Unix compilers.  I haven't seen this but
my informant swears the 9370 VM and VAX/VMS and MS-DOS C compilers all
gag on static func().

Comments?  Send mail, if I get enough replies I'll summarize to the net.

- John.
-- 
 The Beach Bum                                 Big "D" Home for Wayward Hackers
 UUCP: ...!killer!rpp386!jfh                            jfh@rpp386.uucp :DOMAIN

 "You are in a twisty little maze of UUCP connections, all alike" -- fortune

jbeard@quintus.UUCP (Jeff Beard) (05/18/88)

In article <120@pigs.UUCP>, haugj@pigs.UUCP (John F. Haugh II) writes:
> I haven't seen this but
> my informant swears the 9370 VM and VAX/VMS and MS-DOS C compilers all
> gag on static func().
> 

FOR IBM MVS & VM, Bell portable, Waterloo, and SAS compilers
all perform rationally for static func() {}

haugj@pigs.UUCP (John F. Haugh II) (05/20/88)

In article <120@pigs.UUCP>, I write:
] I have been informed that there is some trouble declaring functions to
] be static in most of the non-Unix compilers.  I haven't seen this but
] my informant swears the 9370 VM and VAX/VMS and MS-DOS C compilers all
] gag on static func().
] 
] Comments?  Send mail, if I get enough replies I'll summarize to the net.

No one else has noticed this on MS-DOS or VMS compilers so I suspect the
trouble is with the compiler on the 9370.  (The VM compiler, not the
370/IX version.)  The code in question is mutually recursive and looks
something like:

static	int	func1 ()
{
	int	func2 ();

	...
}

static	int	func2 ()
{
	int	func1 ();

	...
}

From what I've been told, upon seeing `func2' in `static int func2' the
compiler spits out an error message regarding func2.

Is this some new feature of ANSI C?  Does the declaration have to be
of the same form, including storage class???

- John.
-- 
 The Beach Bum                                 Big "D" Home for Wayward Hackers
 UUCP: ...!killer!rpp386!jfh                            jfh@rpp386.uucp :DOMAIN

 "You are in a twisty little maze of UUCP connections, all alike" -- fortune

g-rh@cca.CCA.COM (Richard Harter) (05/21/88)

In article <126@pigs.UUCP> haugj@pigs.UUCP (John F. Haugh II) writes:
>In article <120@pigs.UUCP>, I write:
>] I have been informed that there is some trouble declaring functions to
>] be static in most of the non-Unix compilers.  I haven't seen this but
>] my informant swears the 9370 VM and VAX/VMS and MS-DOS C compilers all
>] gag on static func().
>] 
>] Comments?  Send mail, if I get enough replies I'll summarize to the net.

Mail didn't get through.  Earlier versions of Primos C did not accept static
functions (Primos C is a little eccentric anyway.)  I don't know about current
version because we stripped out all static functions (portable is what actually
works, not what the standards, if any, say should work.)  No problem that I
know of in earlier VMS-VAX C.



-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.

gwyn@brl-smoke.ARPA (Doug Gwyn ) (05/21/88)

In article <126@pigs.UUCP> haugj@pigs.UUCP (John F. Haugh II) writes:
>Is this some new feature of ANSI C?  Does the declaration have to be
>of the same form, including storage class???

Existing compilers were not consistent in their interpretation of linkage
rules.  The correct way (old and new) to forward-reference a static
function is:
	static int func2();
	func1() { /* use func2 here */ }
	static int func2() { }

haugj@pigs.UUCP (John F. Haugh II) (05/28/88)

I earlier posted about some difficulty a client had had compiling a
collection of C code I had written for him.  He had informed me that
he had difficulty compiling the code, as he said, `On a number of
different compilers'.  It turns out the `number' was 1 and the
`different compilers' was the C compiler which is provided with
VM on a 9370.  However, other ANSI-like compilers should have similiar
troubles.

The declarations for the functions causing the trouble were as
follows:

struct	node	*stmt_expr (),
		*smpl_expr (),
		*r_mknode (),
		*st_exp1 (),
		.
		.
		.
		*ag_total ();

with the actual function definition being of the form

static	struct	node	*st_exp1 ()
{
	.
	.
	.
}

Many person wrote that this did not cause them trouble on their
particular compilers.  However, a few people with ``ANSI'' compilers
did mention some grief.  Doug Gwyn, I believe, wrote in a follow
up article, for those of you who missed it, that yes, you must
declare the function to have the same storage class as the actual
function definition itself has.  Thinking back (WAY BACK) I do
recall this ``feature'' being discussed as a way to inform the
compiler that the function linkage may be different for static
functions vs. global functions [ namely that certain segmented
machines may be able to generate `NEAR CALL's vs `FAR CALL's. ]

So in short, all declarations of a function must match the actual
form as the function definition itself.

- John.
-- 
 The Beach Bum                                 Big "D" Home for Wayward Hackers
 UUCP: ...!killer!rpp386!jfh                          jfh@rpp386.uucp :SMAILERS

 "You are in a twisty little maze of UUCP connections, all alike" -- fortune