Discussion:
[mad-user] Question about data strcutures
Deven Phillips
2004-06-24 02:38:19 UTC
Permalink
Hi,

I have written an application which uses libMAD. I was looking at
the code for the library and I find that two things are bothering me:

1. The majority of cleanup functions are just #define'd stubs and
actually do nothing.

2. Why aren't the data structures typedef'd for easier use?

Just curious, and perhaps you can all provide me with a reaonable
explanation that will make me more comfortable with it.

Thanks!!

Deven Phillips
DervishD
2004-06-24 08:26:20 UTC
Permalink
Hi Deven :)
Post by Deven Phillips
1. The majority of cleanup functions are just #define'd stubs and
actually do nothing.
Well, that's because Rob is a good designer ;) Currently those
functions are not needed, but in a future implementation they may be
needed. This way the API is not broken if cleanup functions are
needed in the future. It is, IMHO, a good thing to do.
Post by Deven Phillips
2. Why aren't the data structures typedef'd for easier use?
Well, that's a matter of taste, I'm afraid. I don't know why Rob
has them that way, but I prefer not to typedef structures. In C the
structures are special and there are things that you cannot do with
them, so typedef'ing them is generally not a good idea. It just saves
you from 'typing' the word "struct", and that can be done with any
good editor. And, IMHO, doesn't improve readability, in fact I think
it does exactly the opposite.

BUT, if you are talking about pointers, that's another issue. I
think that typedef'ing pointers to structures to hid the detail that
they are structures is a good point to improve encapsulation. As I
told in a previous message, all pointers share representation, so
there is no point in having something like 'struct mad_header *
whatever' when you can simply have something like 'MAD_HEADER *'. It
is just an object, you cannot dereference it (unless the structure
is defined in a header file, which is the case of 'struct
mad_header').
Post by Deven Phillips
Just curious, and perhaps you can all provide me with a reaonable
explanation that will make me more comfortable with it.
I hope the explanation above is reasonable :) Anyway is Rob who
should give an explanation, since the above views are entirely mine
and may not be the same as Rob's ones ;)

Happy coding :)

Raúl Núñez de Arenas Coronado
--
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/
Loading...