Hello Alex, On 9/4/20 4:50 PM, Alejandro Colomar wrote: >>From 6f3e17cf38bc3718332c7151899e253dbc91affb Mon Sep 17 00:00:00 2001 > From: Alejandro Colomar <colomar.6.4.3@xxxxxxxxx> > Date: Thu, 3 Sep 2020 21:53:51 +0200 > Subject: [PATCH 24/34] queue.3: Use sizeof consistently > > Use ``sizeof`` consistently through all the examples in the following > way: > > - Use the name of the variable instead of its type as argument for > ``sizeof``. > > Rationale: > https://www.kernel.org/doc/html/v5.8/process/coding-style.html#allocating-memory > > Signed-off-by: Alejandro Colomar <colomar.6.4.3@xxxxxxxxx> I don't think this change improves readability. Looking at the code as it is, one can immediately see that it is the same structure being allocated everywhere. After the change, that's not so obvious. I think I won't apply this. Cheers, Michael > --- > man3/queue.3 | 32 ++++++++++++++++---------------- > 1 file changed, 16 insertions(+), 16 deletions(-) > > diff --git a/man3/queue.3 b/man3/queue.3 > index 55cd5847e..2ea5ff4f5 100644 > --- a/man3/queue.3 > +++ b/man3/queue.3 > @@ -559,10 +559,10 @@ struct entry { > > SLIST_INIT(&head); /* Initialize the list. */ > > -n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ > +n1 = malloc(sizeof(*n1)); /* Insert at the head. */ > SLIST_INSERT_HEAD(&head, n1, entries); > > -n2 = malloc(sizeof(struct entry)); /* Insert after. */ > +n2 = malloc(sizeof(*n2)); /* Insert after. */ > SLIST_INSERT_AFTER(n1, n2, entries); > > SLIST_REMOVE(&head, n2, entry, entries);/* Deletion. */ > @@ -775,13 +775,13 @@ struct entry { > > STAILQ_INIT(&head); /* Initialize the queue. */ > > -n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ > +n1 = malloc(sizeof(*n1)); /* Insert at the head. */ > STAILQ_INSERT_HEAD(&head, n1, entries); > > -n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ > +n1 = malloc(sizeof(*n1)); /* Insert at the tail. */ > STAILQ_INSERT_TAIL(&head, n1, entries); > > -n2 = malloc(sizeof(struct entry)); /* Insert after. */ > +n2 = malloc(sizeof(*n2)); /* Insert after. */ > STAILQ_INSERT_AFTER(&head, n1, n2, entries); > /* Deletion. */ > STAILQ_REMOVE(&head, n2, entry, entries); > @@ -975,13 +975,13 @@ struct entry { > > LIST_INIT(&head); /* Initialize the list. */ > > -n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ > +n1 = malloc(sizeof(*n1)); /* Insert at the head. */ > LIST_INSERT_HEAD(&head, n1, entries); > > -n2 = malloc(sizeof(struct entry)); /* Insert after. */ > +n2 = malloc(sizeof(*n2)); /* Insert after. */ > LIST_INSERT_AFTER(n1, n2, entries); > > -n3 = malloc(sizeof(struct entry)); /* Insert before. */ > +n3 = malloc(sizeof(*n3)); /* Insert before. */ > LIST_INSERT_BEFORE(n2, n3, entries); > > LIST_REMOVE(n2, entries); /* Deletion. */ > @@ -1233,16 +1233,16 @@ struct entry { > > TAILQ_INIT(&head); /* Initialize the queue. */ > > -n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ > +n1 = malloc(sizeof(*n1)); /* Insert at the head. */ > TAILQ_INSERT_HEAD(&head, n1, entries); > > -n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ > +n1 = malloc(sizeof(*n1)); /* Insert at the tail. */ > TAILQ_INSERT_TAIL(&head, n1, entries); > > -n2 = malloc(sizeof(struct entry)); /* Insert after. */ > +n2 = malloc(sizeof(*n2)); /* Insert after. */ > TAILQ_INSERT_AFTER(&head, n1, n2, entries); > > -n3 = malloc(sizeof(struct entry)); /* Insert before. */ > +n3 = malloc(sizeof(*n3)); /* Insert before. */ > TAILQ_INSERT_BEFORE(n2, n3, entries); > > TAILQ_REMOVE(&head, n2, entries); /* Deletion. */ > @@ -1426,16 +1426,16 @@ struct entry { > > CIRCLEQ_INIT(&head); /* Initialize the queue. */ > > -n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ > +n1 = malloc(sizeof(*n1)); /* Insert at the head. */ > CIRCLEQ_INSERT_HEAD(&head, n1, entries); > > -n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */ > +n1 = malloc(sizeof(*n1)); /* Insert at the tail. */ > CIRCLEQ_INSERT_TAIL(&head, n1, entries); > > -n2 = malloc(sizeof(struct entry)); /* Insert after. */ > +n2 = malloc(sizeof(*n2)); /* Insert after. */ > CIRCLEQ_INSERT_AFTER(&head, n1, n2, entries); > > -n3 = malloc(sizeof(struct entry)); /* Insert before. */ > +n3 = malloc(sizeof(*n3)); /* Insert before. */ > CIRCLEQ_INSERT_BEFORE(&head, n2, n3, entries); > > CIRCLEQ_REMOVE(&head, n2, entries); /* Deletion. */ > -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/