🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by chmilar@cpsc.uca Mon, 06 Mar 1989 19:12
Mixing C++ with ANSI C
#2711
Author: chmilar@cpsc.uca
Date: Mon, 06 Mar 1989 19:12
51 lines
1852 bytes

I have recently ported the AT&T C++ translator to a machine that
has a pseudo-ANSI C compiler (the SGI Iris-4D/20).  A problem
has arisen due to the interaction of the two compilers.  The
essence of the problem is this:

A header file is given to C++ with this declaration:

    void ortho( float, float, float, float, float, float );

The C code generated has the prototype stripped out:

    void ortho();

When ortho is called in the C++ code:

    ortho( -2.0, 2.0, -2.0, 2.0, -2.0, 2.0 );

the C code is this:

    ortho( (float)(-2.0), (float)2.0, (float)(-2.0), [...] );

but, in fact, the parameters will be converted to doubles before
being passed, as is expected.  However, ANSI C specifies that if
the parameters are declared as "float" in a function prototype,
they will be passed as single-precision floats!

In the example above, the arguments _should_ be passed as floats
rather than as doubles.  Because C++ removes the prototypes
from the "ortho" declaration, they are passed as doubles.

Has anyone found a way to circumvent this problem in a nice way?
I have resorted to putting "wrappers" around the offending functions
to get the arguments passed correctly.  I have also tried a nasty
kludge where I pass a struct containing one float - this doesn't
work due to a difference between floating point and general-purpose
registers on the 4D.  What I would really like is to have the C++
translator spit out the function prototypes intact; there does not
appear to be a compiler switch to accommodate this, and I don't
want to start hacking on the code.  Will this need be addressed in
future releases of the C++ translator?

If you have a solution to this dilemma, please send me some mail.

Thank-you

Michael Chmilar,  University of Calgary,
.{ubc-cs,utai,alberta}!calgary!chmilar

	"What's your sign?"  "It depends on my angle!"
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads