From: Yann Droneaud <ydroneaud@opteya.com>
To: gcc@gcc.gnu.org
Subject: alignof(type, field); sizeof(type, field); typeof(type, field): getting type information on nested field
Date: Tue, 02 Jul 2019 07:57:00 -0000 [thread overview]
Message-ID: <dac00bd0f08f74c2c591402ecb0bb65dc28d6a84.camel@opteya.com> (raw)
Hi,
I'm sometime in need to "probe" the size, the type, (and less often the
alignment) of a field inside a structure.
In such case I have to write "ugly" thing like
struct A
{
struct
{
type_t t;
} B;
};
typeof(((struct A *)NULL)->B.t) V;
It would have been some much pleasing to have 2 parameters version of
sizeof(), typeof(), and alignof(), which would look like a lot like
offsetof() usage:
typeof(struct A, B.t) V;
if (sizeof(struct A, B.t) != sizeof(long)) ... ;
if (alignof(struct A, B.t) < alignof(long)) ... ;
As sizeof is an operator, this is not straightforward to implement.
Currently sizeof (0, variable); is a valid construct, giving the size
of "variable".
Hence, turning sizeof() to a variadic function-like thing would break
existing code.
Maybe it would possible to add such function-like operator as _Sizeof()
? And have a header #define'ing sizeof(...) as _Sizeof() for code
wanting the new behavior ?
Is this possible ? Is such feature was already considered ?
Regards.
--
Yann Droneaud
OPTEYA
next reply other threads:[~2019-07-02 7:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-02 7:57 Yann Droneaud [this message]
2019-07-02 8:32 ` Jonathan Wakely
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dac00bd0f08f74c2c591402ecb0bb65dc28d6a84.camel@opteya.com \
--to=ydroneaud@opteya.com \
--cc=gcc@gcc.gnu.org \
/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).