[gdal-dev] Re: C/C++ Divide

Brian Koehler bkoehler at h...
Wed Nov 18 03:26:19 EST 1998


Frank writes:

>
>Should I just have two sets of types for each application visible class.
>One a C ``handle'' type which gets cast to a C++ type within the C
>jacket functions? In this case we would need to have two names, one
>for the C handle type, and one for the C++ class.
>
>eg.
>
>typedef void *GDALDatasetH;
>
>#ifdef __cplusplus
>class GDALDataset;
>#endif
>
>int GDALGetRasterXSize( GDALDatasetH hDS )
>
>{
> GDALDataset *poDS = (GDALDataset *) hDS;
>
> return( poDS->GetRasterXSize() );
>}
>

I like this idea. It even suggests to me that there might be a way
of automatically generating the types and cover functions from
the C++ header files (see below).

>Should I just abandon C++ classes, and do everything with C linkage, no
>methods, and just use a C++ compiler as a better C compiler?
>

No. If it were me, I would do everything in C++ and just be careful with
the application callable classes so C cover functions like the one above
can be created easily.

>Should I worry less about the C linkage API, and just graft cover functions
>over a clean, application visible C++ implementation?
>

Yes.

>Also, what API should I provide documentation for? Given how much fun
>documenting APIs are, I would prefer to write the documentation once,
>perhaps just showing two prototypes, once for C and one for C++, but
>argument handling and so forth the same for both language. This might
>extend well to other languages if I don't do anything too tricky with
>arguments. For instance, I might avoid C++ polymorphism, or defaulted
>arguments.

Probably a good idea at the top level.

This whole discussion has got me thinking: wouldn't it be cool if there
was a tool that took a C or C++ API and generated the appropriate
C cover functions and whatever else was required to link up with another
language such as C/Java/Perl/Python/Tcl. Something like:

c++api_to_{C,Java,Perl,Python,Tcl} some_c++_api.h

which would spew out all the required code which is a pain
to do by hand now, not to mention boring.

Anyway, I guess I'm getting off track. I hope this list doesn't
have to be moderated now :-)

Brian


P.S. Frank, I haven't been able to access your site on your home
computer (to see the source for example) in a long time, like following the
link
that was in the message that this a reply to. Is this just bad luck on my
part
or is there a bigger problem.



------------------------------------------------------------------------
Free Web-based e-mail groups -- http://www.eGroups.com





More information about the Gdal-dev mailing list