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

Neil Johnson neil.johnson97 at ntlworld.com
Wed Mar 30 16:06:29 CEST 2011


Typedef creates a synonym for an existing type, it does not in and of
itself create a new type. Like any feature in C (or any other
language) it has its uses, but it can also be misused, either by those
who *really* know what they're doing, or those who simply *don't*.

Not understanding a concept does not make the concept dumb, it is more
a comment about the commenter...

Neil


On 30/03/2011, Jay Vaughan <jayv at synth.net> wrote:
> I agree, typedef is really useless.
>
> ;
> --
> seclorum
>
> On Mar 30, 2011, at 14:02, Thomas Strathmann <thomas at pdp7.org> wrote:
>
>> 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
>> _______________________________________________
>> Synth-diy mailing list
>> Synth-diy at dropmix.xs4all.nl
>> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
> _______________________________________________
> Synth-diy mailing list
> Synth-diy at dropmix.xs4all.nl
> http://dropmix.xs4all.nl/mailman/listinfo/synth-diy
>


-- 
http://www.njohnson.co.uk



More information about the Synth-diy mailing list