[sane-devel] sane.h misses extern "C"

Rene Rebe rene@rocklinux-consulting.de
Wed, 14 Jul 2004 19:55:27 +0200 (CEST)


Hi,

On: Mon, 12 Jul 2004 20:17:27 +0200,
    Mattias Ellert <mattias.ellert@tsl.uu.se> wrote:

> >>Is there a good reason why the installed sane.h misses the usual
> >>header lines needed for compilation with C++?
> > =

> > Well, it's a C and not a C++ header and these #ifdefs are ugly :-)
> =

> If you put them in the header file you only need them once. Since the=
y =

> are not in the header files you have to do
> =

> extern "C" {
> #include <sane/sane.h>
> }
> =

> in every c++ file. I think this is more "ugly". Having the extern =

> declaration in one single place (i.e. in the header file) makes so mu=
ch =

> more sense than having to put in in every single file where you inclu=
de it.
> =

> You don't have to do this kind of hack for normal system header files=
. =

> Almost all other header files have the extern "C" declaration (or the=
 =

> equivalent __BEGIN_DECLS __END_DECLS pair).

Yes - ack. This is the way nearly any other system header is prepared .=
..

> > Isn't it a better solution to use the extern "C" when including the=

> > file in the C++ .C code if you really want to use sane.h in C++? Or=
 do
> > we get trouble this way because it includes the structs?
> =

> I think having them in the header file is "the better solution".

Sure - I just quick fixed it in my example app by doing so ... But I
just wanted to note it publicly that we miss it ...

I fully agree that C/C++ users assume including "some random" header
will just work.

I can only imagine one drawback - that current C++ projects (kooka)
that include the "defect" header that have a private fix by
surrounding the inclusion with the extern "C" declaration could
fail. But at least with gcc 3.4.1 this is not the case - just tested
it (I guess the old ones accept it, too).

> >>May I just commit them to CVS?
> =

> I would say YES.

Any other votes ,-)? =


Sincerely yours,
  Ren=E9 Rebe

--  =

Ren=E9 Rebe - Europe/Germany/Berlin
  rene@rocklinux.org rene@rocklinux-consulting.de
http://www.rocklinux.org http://www.rocklinux-consulting.de