[GRASS-dev] computational geometry in C++ library

Glynn Clements glynn at gclements.plus.com
Fri May 5 19:58:25 EDT 2006


Francesco Paolo Lovergine wrote:

> > > Calling C funcs from C++ is straight-forward. 
> > > The reverse is not possible, the whole result would be a C++ prog.
> > 
> > It's not quite that bad. You can write C-callable wrapper functions in
> > C++, e.g.:
> > 
> > 	extern "C" {
> > 	
> > 	void wrapper(void *p)
> > 	{
> > 		((Object *) p)->method();
> > 	}
> > 	
> > 	}
> > 
> > Note that the GLU library is written in C++, but can be used from C
> > programs.
> > 
> 
> Oh, yes, but that's C++, isn't it?

Yes.

> The resulting code will link C++
> objects with all consequent headaches (e.g. obscure ABI changes from 
> time to time) and C++ run-time on the shoulder. 
> That's what I pointed with my first sentence, C code can be called 
> by C++, but not viceversa.

Er, the above is C++, but it can be called from C.

GRASS code should avoid using C++ where possible, but we already
depend upon some libraries which are written in C++, most notably
GDAL, which is a mandatory dependency in 6.x.

If there's a particularly useful third-party library, we shouldn't
ignore it just because it is written in C++. However, anything which
uses it should first create a set of C wrappers (if the the library
doesn't already provide them) and use those, rather than using the C++
interface directly. If more than one module uses the library, the C
interface should either be made into a library or, where possible,
contributed back for inclusion into the original library.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list