[vorbis-dev] vorbisfile API ickiness

Jonathan Blow jon at bolt-action.com
Wed Nov 8 04:14:27 PST 2000



So I'm using vorbis in a game engine that I am writing.
And the way things are declared in vorbisfile is causing great
inconvenience because by interacting with the thing I hate most
about C++: that you have to declare things that should be private
in header files.

I have this class that basically talks to vorbisfile and returns
me PCM samples.  That class needs to have an OggVorbis_File
member, of course.  So it should look something like this:

    struct Vorbis_Decoder {
        // ... blah blah blah, a bunch of stuff

        OggVorbis_File my_vorbis_file;
    };

Now the problem is that nobody can include vorbis_decoder.h
without including the vorbis and vorbisfile includes, which
really sucks.  In a large project, compile time goes through
the roof.  So the way I usually manage this is to eat a slight
bit of inconvenience, declare the offending type as a pointer,
and dynamically allocate it inside the class.  Because the
size of the pointer is known, without the pointer needing
to be known, everything is fine.  Any part of my system
that wants to include vorbis_decoder.h can do so, without
including a slew of other vorbis headers:

    struct OggVorbis_File;

    struct Vorbis_Decoder {
        // ... blah blah blah, a bunch of stuff

        OggVorbis_File *my_vorbis_file;
    };

This is what I usually do and it works just great, except it
does not work in the case of vorbisfile because here is how
OggVorbis_File is defined:

    typedef struct {
        // ... blah blah blah, more stuff
    } OggVorbis_File;

The problem with this is that some anonymous struct type is
being created, and then aliased to OggVorbis_File... but
the fact that the base type is anonymous prevents me from
forward declaring OggVorbis_File like I want to (another
stupidity of C++).  
 
However, if it were defined like this, everything would work
great:

    struct OggVorbis_File { 
        // ... blah blah blah, more stuff
    };

Is there a problem with this?  It has been forever since
I programmed in C but I see in my ANSI version of the K&R book
that it is legal.  Is it not legal in K&R C or something?

To get around this, right now I have a void * in the header
file, and some nasty macros that cast it in the .cpp file.
It sucks.

   -Jonathan.

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list