bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Cc: Paul Eggert <eggert@cs.ucla.edu>
Subject: Re: [PATCH] flexmember: update comment
Date: Sat, 25 May 2019 00:17:11 +0200	[thread overview]
Message-ID: <1616776.HnN4KKd12v@omega> (raw)
In-Reply-To: <20190524220133.31145-1-eggert@cs.ucla.edu>

Hi Paul,

> +       Use 'FLEXSIZEOF (struct s, d, N)' to calculate the size in bytes
> +       of such a struct containing an N-element array, as both
> +       'sizeof (struct s) + N * sizeof (char)' and
> +       'offsetof (struct s, d) + N * sizeof (char)'
> +       might compute a size that can cause malloc to align storage
> +       improperly, even in C11.

I'm confused.

1) What is the alignment problem if the array element type is 'char'?
I would understand an alignment problem if it is 'double'. But with 'char'?
'char' has the size 1, and - except on m68k - also the alignment 1.

2) If
     (struct s *) malloc (offsetof (struct s, d) + N * sizeof (char))
should be avoided in favour of
     (struct s *) malloc (FLEXSIZEOF (struct s, d, N))
don't we need to apply a 'ceil'-like alignment to the malloc result?

Bruno



  reply	other threads:[~2019-05-24 22:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-24 22:01 [PATCH] flexmember: update comment Paul Eggert
2019-05-24 22:17 ` Bruno Haible [this message]
2019-05-24 22:46   ` Paul Eggert
2019-05-24 23:33     ` Bruno Haible
2019-05-25  0:34       ` Paul Eggert
2019-05-25 13:07         ` Bruno Haible

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1616776.HnN4KKd12v@omega \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=eggert@cs.ucla.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).