[PATCH] do proper typecasting on malloc() and calloc() calls

Radoslaw Szkodzinski astralstorm at gorzow.mm.pl
Tue Mar 21 15:41:48 UTC 2006


On Tuesday 21 March 2006 00:52, Eric Hopper wrote yet:
> But, stricter checking for void * was not added into C++ to encourage
> the use of static_cast. 

Well, I'm not a C++ historian.

> The rule was added before static_cast was 
> added.  It was also not added for reasons involving any sort of stupid
> zealotry other than a desire to avoid having a type system that was any
> more liberal than it absolutely had to be.

It's not really much more liberal, except it allows some things to work better 
in C (like NULL and malloc)

>
> In C++, you have the 'new' operator.  And it generates a pointer of the
> correct type.  The biggest reason for the 'void * will freely convert to
> anything' rule in C (which was added in C90) was to avoid just the sort
> of ugliness this patch perpetrates.  But it's also a form of ugliness
> that simply doesn't happen in properly written C++, so the rule is not
> needed there.
>

I do understand that one rarely mallocs anything in C++ or fudges with 
pointers. However, one rare and easy to handle special case against breaking 
proper C code just doesn't seem like a good trade-off for me.
C++ isn't compatible with C as it stands now. E.g. varargs and other C99 
features.

> In much the same way as it irritates me when people say that Mercurial
> was inspired by git,

Yes, the relation is superfluous only. Mercurial has a very different 
repository format and different assumptions.

> I think [the patch is] really of dubious worth, but the the C code 
> is also very tiny and rarely touched, so making it slightly uglier in
> order to make it easier to compile Mercurial somewhere might be worth
> it.

Submitting to ugliness is the first step to disaster.

-- 
GPG Key id:  0xD1F10BA2
Fingerprint: 96E2 304A B9C4 949A 10A0  9105 9543 0453 D1F1 0BA2

AstralStorm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20060321/7cc3e0bd/attachment-0001.asc>


More information about the Mercurial mailing list