[vorbis-dev] Re: vorbisfile updates, and a couple of questions
Greg Stark
gsstark at mit.edu
Sat Apr 22 13:27:13 PDT 2000
Jonathan Blow <jon at bolt-action.com> writes:
> > Casting function pointers appears
> > to be a rather arcane sort of thing to do. Anyone with more C clues than I
> > care to speak up?
>
> The syntax for that has got to be hairy... what I would do is make typedefs
> for both types, and then cast one to the other. So...
You might be better off keeping this simpler:
typedef int (*vorbis_callback)(void *closure, vorbis_op *op);
int my_read_callback(void *closure, vorbis_op *op) {
FILE *input = (FILE*)closure;
assert(op->operation == VORBIS_READ);
...
}
int my_write_callback(void *closure, vorbis_op *op) {
...
This means you can't just pass fread et al as callbacks, but it avoids having
hairy casts and different callbacks depending on whether the closure is a
FILE* or an opaque object. It does have one major disadvantage, you can't add
stuff to the vorbis_op structure without invalidating old code, which is
annoying.
--
greg
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
More information about the Vorbis-dev
mailing list