Re: [PATCH] btree: Add custom allocator interface.
Stuart Longland <[email protected]> Tue, 9 Feb 2016 12:14:59 +1000
| Newsgroups | org.ozlabs.lists.ccan |
|---|---|
| Message-ID | <[email protected]> |
On 09/02/16 09:40, David Gibson wrote:
> On Mon, Feb 08, 2016 at 02:26:29PM +1000, Stuart Longland wrote:
>> On 08/02/16 12:17, David Gibson wrote:
>>>> +static void* default_malloc(const struct btree_allocator* alloc, size_t size);
>>> Existing style in this function suggests "void *foo" rather than
>>> "void* foo".
>>
>> Ahh, call it habit, I'm used to having the "pointer" bit with the type
>> (as to me; "pointer to void" is a distinct type from "void"). Caught
>> myself doing it elsewhere but missed it here, I'll fix it.
>
> So, from a language design point of view, I agree with you. However,
> I dislike that style in C because it obscures the fact that C
> importantly *does not* have that sensible handling of types.
>
> More specifically this style:
> int* a, b;
>
> Suggests that a and b have the same type, but of course they don't.
Yeah, for that reason I tend to write:
int* a;
int* b;
thus being explicit about it. In fact I do that for non-pointers too as
it's just clearer. (I'd make lousy submissions to the IOCCC.)
It also lets me document what each variable is doing with a comment.
However, we digress, the style is definitely the 'void *foo' style
already, and so in the interests of code consistency, that shall be the
style used. ;-)
>>> [snip]
>>>>> +/* Default allocator implementation */
>>>>> +const struct btree_allocator BTREE_DEFAULT_ALLOCATOR = {
>>> Use of all-caps for a non-macro is a bit unexpected.
>>>
>>
>> Good point. I guess I wanted to visually differentiate a constant from
>> other member types.
>
> I applaud the idea, but unfortunately I don't think that use of caps
> is common enough to make it really clear.
Yeah, I did it without thinking, elsewhere like in Python, that's the
convention; ALL_CAPS → constant. I know C has a convention for macros
being capitalised, but none really for const members, my fingers just
went on autopilot.
I shall fix this though when I get to everything else. :-)
Regards,
--
Stuart Longland (aka Redhatter, VK4MSL)
I haven't lost my mind...
...it's backed up on a tape somewhere.
_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
signature.asc
(application/pgp-signature, 819 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJWuUukAAoJEE36GRQQveO3V6wQAI0+LPf7d93X8qeHnEBO4Bci KfLGklV0ELkisovXyNwSy74woDO+uQCGiguhuHgqnd+/UlwCgc3t4GBURbmb2oTy tKIZa6sj9JDldN1DngQEPZSIYGuUvlxyaD9EmOERX/uoQXeBlCavM6o7UzdDVB5X nBGykhNQCB49kGii1O2KUEiw/modFa+c0PryF9Nfxq3kFxZdmVt/Li3VgqZpImq0 2NaYL3EXstpjC9Pk6AYSMP6T8VaO8TiHoU1gANj0Fyeah1lsaHtpVdWgHHO1578Z l+7sAvLSe/77N4NNVn2azSXyGvq5je4vWPdL6zOkE8jGGG/V4pWp/0OdWhAXx5dT d+DsKSQQlA4UHcB8f+wg8M7Onpqrm2/d3ymIdWj2c33w2hzeh56IQ56/3vsPdqLf 5zf0hsxeTH6PxK2X6+Bc2G3XWJGzkCQzK4jO403QZhGHkzqa+Sz1PImTvCZh3VIw 3bD9M/GvgBY/kcYiKcE6hunBDAgOb5Mv+kOH9tsZ6HGyqP8ld0orpb/xE1tWeBYF 6LNewCQxh9dy3UFMG8rz9rCDSvbAyL8U+pMu/m0sNBL+RkNuFir7FppciZ7B2y+w 2lQ033fBaAVO5x7IFysDRo+UULN+/LImT2sL5yHrtB1OlRlhgABFw9Y7MOGrFwY/ 60TDIB3nmqYHBSovxAv1 =Fe08 -----END PGP SIGNATURE-----