Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bionet!agate!ucbvax!tut.cis.ohio-state.edu!rutgers!att!alberta!calgary!cpsc!chmilar From: chmilar@cpsc.ucalgary.ca (Michael Chmilar) Newsgroups: comp.lang.c++ Subject: Mixing C++ with ANSI C Message-ID: <844@cs-spool.calgary.UUCP> Date: 6 Mar 89 19:12:22 GMT Sender: news@calgary.UUCP Lines: 50 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!"