Sujet : Re: Which code style do you prefer the most?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 26. Feb 2025, 14:26:41
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vpn4qi$2j0hq$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 26.02.2025 12:59, Ar Rakin wrote:
Lawrence D'Oliveiro <ldo@nz.invalid> writes:
[...]
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.
For longer structures it may help as documentation and orientation.
Personally (in "C") I prefer '//' though. - In a language like "C"
that is cluttered with punctuation characters I avoid using yet more
'*' and '/' symbols where possible to not make it yet more unreadable.
Generally (in other languages) I prefer if they support such comments
as part of their syntax; e.g. in Simula 67 you may append an optional
comment after an 'end' without further syntactical ballast. In Eiffel,
OTOH, they show optional comments (as part of their syntax) after e.g.
class/procedure 'end' tokens, but with the usual comment '--' token.
Janis