[m-dev.] for review: Avoid including mercury_imp.h in generated .h files.

Fergus Henderson fjh at cs.mu.OZ.AU
Sun Aug 30 14:37:53 AEST 1998


On 24-Aug-1998, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> > "mercury_imp.h" or at least "mercury_types.h" is needed
> > for the types `Integer', `Float', etc. that may be included in the
> > generated header files.  If `MERCURY_EXCLUDE_IMP_H' is defined,
> > then these symbols will be undefined, which will lead to compile errors.
> > 
> > Did I miss something?
> 
> Imagine foo.h is a generated .h file.
> 
> - You can include foo.h in your C++, but it will complain that it cannot
>   find mercury_imp.h, so you will have to put an include path into your
>   g++ compile command.  But this is installation-dependent, so you can't
>   do it in general very easily. 

Why not use a solution similar to that used by gcc:  have an option (or
a command) which prints out the installation-dependent path?
GNU C has an option `-print-libgcc-file-name' which is used for printing
out the path to libgcc.a.  It would be easy to add an option to mgnuc
to print out the include path for the Mercury runtime's C header files.
Then you just use

	CXX = g++
	CXXFLAGS = -I`mgnuc --print-include-path`

in your Makefile or Mmakefile.

> - mercury_types.h might be what you want,

Yes, indeed I strongly suggest that it *is* what you want.

>   but mercury_imp.h includes
>   everything, including register defintions, which we most certainly
>   don't want.

Agreed.  So change the generated #include in the generated header file
to include mercury_types.h instead of mercury_imp.h.

> So you come down to a choice between turning mercury_imp.h off and
> adding a few #defines by hand to get things working,

These #defines are also installation-dependent.
So I don't think this is a good solution.

> and adding a lot of
> complexity to your application which wants to use C++.
> 
> A better solution is to support compiling C++ using mmake, which sets
> the include paths and -D options for you.

Actually it is `mgnuc' not `mmake' which sets those.

Mmake already supports compiling C++: you just have to add
appropriate rules to your Mmakefile.

> But for the application I
> am thinking of, there simply isn't enough time to muck around with
> such things.

The change to mgnuc mentioned above would be quite easy.
The change to mmc to generate `#include "mercury_types"'
instead of `#include "mercury_imp"' should be trivial.

So how does that sound?

Cheers,
	Fergus.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.



More information about the developers mailing list