[sdiy] OT (but very synthy): C question

Thomas Strathmann thomas at pdp7.org
Wed Mar 30 14:02:41 CEST 2011


On 3/30/11 13:05 , Tom Wiltshire wrote:
> It's annoying that in C you can forward-declare a struct, but can't do the same thing with a typedef.
> The following is possible..
>
> typedef struct LFO LFO;
>
> ..but this just forward-declares the struct, then creates a type from it. Since it's a definition (of a new type) you can't use this like you would a forward declaration. If you attempt to, you'll get a "redefinition of typedef" error.
> This means that you finish up having to scatter the 'struct' keyword all over your function prototypes (like Olivier does below) because you can't typedef the struct again, and makes the 'typedef' keyword considerably less useful than it could have been in my view.

For whatever it's worth, I'm actually in favour of using the struct 
keyword instead of using typedef. It might not be that pretty, but at 
least you know exactly from the type-signature of a function prototype 
what kind of values it deals with without having to look up the 
user-defined types first. I consider it a little more readable, but YMMV.

	Thomas



More information about the Synth-diy mailing list