Deutsch   English   Français   Italiano  
<87v7swzzl7.fsf@onesoftnet.eu.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Ar Rakin <rakinar2@onesoftnet.eu.org>
Newsgroups: comp.lang.c
Subject: Re: Which code style do you prefer the most?
Date: Wed, 26 Feb 2025 17:59:16 +0600
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <87v7swzzl7.fsf@onesoftnet.eu.org>
References: <vpkmq0$21php$1@dont-email.me> <vplhc7$26ur1$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Wed, 26 Feb 2025 12:59:17 +0100 (CET)
Injection-Info: dont-email.me; posting-host="3819d60e36b63f24b1100dea27559741";
	logging-data="2675633"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+Jmuj+xw4ep2mrtyi2Le1Hw5M//ofhYqI="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:hqqSfHez8L3c/jF9+xtV6RqbXNw=
	sha1:NkHxa++GMFimFOqKRy2VWSElWgM=
Bytes: 2307

Lawrence D'Oliveiro <ldo@nz.invalid> writes:

> On Tue, 25 Feb 2025 21:15:12 +0600, Ar Rakin wrote:
>
>> Which one of the following do you prefer the most?
>
> None of them:
>
> struct malloc_chunk /* header on each memory block */
>   {
>    struct malloc_chunk *next; /* doubly-linked list */
>    struct malloc_chunk *prev;
>    bool is_free;
>    size_t size;
>   } /*malloc_chunk*/;
>
> static inline void * get_chunk_ptr
>   (
>     struct malloc_chunk * chunk
>   )
>   /* returns pointer to the memory block excluding the header. */
>   {
>      return
>         (void *)(chunk + 1);
>   } /*get_chunk_ptr*/
>
> void * malloc
>   (
>     size_t size
>   )
>   /* allocates a memory block of the specified size,
>     or NULL if none available. */
>   {
>     struct malloc_chunk * chunk = mm_find_chunk
>       (
>         /*size = */ size,
>         /*type =*/ MM_CHUNK_FREE
>       );
>     if (chunk == NULL)
>       {
>         chunk = mm_alloc_chunk(size);
>       } /*if*/
>     return
>         chunk != NULL ?
>             get_chunk_ptr(chunk)
>         :
>             NULL;
>   } /*malloc*/

The comments after each closing brace looks a bit weird to me. Even in
GNU codebases the only time I have ever seen them doing that is when
using #ifdef/#ifndef preprocessor directives.