[comp.os.os9] OSK C Compiler problem with No. of Args

knudsen@cbnewsd.att.com (michael.j.knudsen) (04/26/91)

This isn't a bug (maybe), but something I found while porting a
large program from OS-9/6809 to OS-K.

If one of your functions is defined as taking N arguments,
then your calls to that function had better have exactly N arguments,
no less!  (Maybe more is OK; not tried).
I mean omitting args off the end, not out of the middle -- no
compiler could figure that out!

6809 C, which pushes all args in reverse order on the stack,
is very tolerant about missing arguments if the other args' values
tell the function code not to reference the missing ones.

But OSK C does strange things sometimes if not all args are present.
I know it puts the first two args in regs d0 and d1, then pushes
the rest on stack, in [I hope] reverse order.

Anyway, just another sloppy programming practice that you can't get
away with any more.
-- 
"What America needs is A Thousand Points When Lit..."

	knudsen@iceland.att.com

blarson@blars (04/26/91)

In article <1991Apr25.174038.7834@cbnewsd.att.com> knudsen@cbnewsd.att.com (michael.j.knudsen) writes:
>This isn't a bug (maybe)

Definatly not a bug.

>If one of your functions is defined as taking N arguments,
>then your calls to that function had better have exactly N arguments,
>no less!  (Maybe more is OK; not tried).

More is definatly OK, and if you want to do a variable number I
strongly recomend my varargs.h.  (Smilodon.cs.wisc.edu has at least
two copies: mg and blarslib both contain it.  Let me know if it should
be uploaded separatly.)

>But OSK C does strange things sometimes if not all args are present.
>I know it puts the first two args in regs d0 and d1, then pushes
>the rest on stack, in [I hope] reverse order.

The register use gets more complicated if you ever use floating point.
You realy shouldn't care what order things are pushed in unless you
are writing a varargs.h or stdarg.h package, which should be included
with the C compiler so only the compiler author needs to worry about
it.  (Stdarg.h can't be done without compiler support on OSK.)

>Anyway, just another sloppy programming practice that you can't get
>away with any more.

Any more???  Useing this sloppy programming practice was taking
advantage of a compier bug, (that it didn't diagnose the condition) and
never should have been counted on.



-- 
blarson@usc.edu
		C news and rn for os9/68k!
-- 
Bob Larson (blars)	blarson@usc.edu			usc!blarson
	Hiding differences does not make them go away.
	Accepting differences makes them unimportant.

knudsen@cbnewsd.att.com (michael.j.knudsen) (04/30/91)

In article <195@blars>, blarson@blars writes:
> More is definatly OK, and if you want to do a variable number I
> strongly recomend my varargs.h.  (Smilodon.cs.wisc.edu has at least

I saw a varargs.h once and just about choked looking at the size
and complexity.  And I can't get stuff from smilodon, etc.
Tho I appreciate the suggestion, thanks.

Variable numober of args works simply in the 6809 compiler since
the args are pushed in right-left order.  And should work just as
well in 68K once D0 and D1 get used up.  Yes, I know that double
floats take up two positions.

Incidentally, the 6809 printf() calls just push the args on,
no special varargs.h stuff.

> Any more???  Useing this sloppy programming practice was taking
> advantage of a compier bug, (that it didn't diagnose the condition) and
> never should have been counted on.

Not a bug, just the obvious, elegant, simple way that 6809 works.
And even the OSK compiler (which tries to play Lint, and has caught
some nasty stuff for me) could'nt catch this if it's spread across
multiple source files.
-- 
"What America needs is A Thousand Points When Lit..."

	knudsen@iceland.att.com