Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

extending Snack in C++?

7 views
Skip to first unread message

Ralf Fassel

unread,
Nov 9, 2009, 2:39:03 PM11/9/09
to
I'm trying to extend the Snack library version 2.2.10 by c++ but am
running into compilation errors like the following:

% cat foo.cxx
// foo.cxx
#include <snack.h>
// End of file
% g++ -I .../path-to-snack-headers -c foo.cxx
In file included from snack.h:33,
from foo.cxx:2:
jkSound.h:307: error: declaration of 'int (* SnackFileFormat::getHeaderProc)(Sound*, Tcl_Interp*, Tcl_Channel_*, Tcl_Obj*, char*)'
jkSound.h:275: error: changes meaning of 'getHeaderProc' from 'typedef int (getHeaderProc)(struct Sound*, struct Tcl_Interp*, struct Tcl_Channel_*, struct Tcl_Obj*, char*)'
...

In C this compiles fine:
% g++ -xc -I $SIXXBASE/include/si++ -c foo.cxx

Obviously the snack structs are not c++ compatible although the headers
have some #ifdef __cplusplus markers in them.

I've tried some combinations, but short from duiplicating the relevant
structs in C++ using different namings I'm running out of ideas...

Some tips anyone?

What I'm trying to do is to add some customized filters to massage the
sound as it is played...

R'

Konstantin Khomoutov

unread,
Nov 10, 2009, 11:33:04 AM11/10/09
to
On Nov 9, 10:39 pm, Ralf Fassel <ralf...@gmx.de> wrote:

> I'm trying to extend the Snack library version 2.2.10 by c++ but am
> running into compilation errors like the following:

[...]

May be you should do

// foo.cxx
extern "C" {


#include <snack.h>
}
// End of file

instead?

Ralf Fassel

unread,
Nov 11, 2009, 5:12:37 AM11/11/09
to
* Konstantin Khomoutov <khom...@gmail.com>

| May be you should do
| // foo.cxx
| extern "C" {
| #include <snack.h>
| }
| // End of file
| instead?

Doesn't help. The problem is that in C++ you can't have structs
(==classes) with members having the same name as a typedef:

typedef int foo;
struct x {
foo foo;
};

is not valid in C++ (while it is in C), and the Snack headers use this
idiom a lot.

% g++ -c foo.cxx
foo.cxx:4: error: declaration of 'foo x::foo'
foo.cxx:2: error: changes meaning of 'foo' from 'typedef int foo'

If you tell the compiler this is really "C" it works:
% g++ -xc -c foo.cxx

extern "C" only changes the name mangling, not the syntax rules...

R'

0 new messages