From: Derek M Jones <derek@knosof.co.uk>
To: Alexey Zaytsev <alexey.zaytsev@gmail.com>
Cc: David Given <dg@cowlark.com>,
linux-sparse@vger.kernel.org, Josh Triplett <josh@kernel.org>
Subject: Re: [PATCH 2/15 v2] Unhardcode byte size being 8 bits.
Date: Thu, 18 Dec 2008 01:10:30 +0000 [thread overview]
Message-ID: <4949A306.2060200@knosof.co.uk> (raw)
In-Reply-To: <f19298770812171633w43707eb0h8c0a0be262549ddf@mail.gmail.com>
Alexey ,
>>> unsigned long test1(void *p)
>>> {
>>> return sizeof(*p);
>>> }
>> TBH, I don't think that's legal --- I know of several compilers that
>> will refuse to compile it, and gcc -pedantic produces a warning, which
>> means it probably falls into the 'undefined behaviour' bucket of the
>> standard. I can't find anything that specifically talks about sizeof
>> void, but 6.3.2.2.1 prohibits doing *anything* with the result of an
>> expression of type void, which sort of applies here.
>>
>> Of course, I'm thinking about this from the sparse-as-a-compiler point
>> of view, where you're probably more interested in replicating gcc's
>> behaviour.
>
> This seems to be legal, and quite popular in the Linux kernel. GNU C defines
> sizeof(void) being 1.And as it has the -Wpointer-arith flag, this kind of stuff
> may be caught without sparse if deemed undesirable.
It is a constraint violation.
"The sizeof operator shall not be applied to an expression that has
function type or an incomplete type"
sentence 1118: c0x.coding-guidelines.com/6.5.3.4.html
void is an incomplete type that cannot be completed
sentence 524: c0x.coding-guidelines.com/6.2.5.html
In pre-C90 days, prior to the availability of void, char * was
often used in a context where void * is now used. Treating void
as being equivalent to char in some kind of compatibility mode
makes sense. It looks like the gcc maintainers have over stepped
the mark.
I have reported the bug in gcc. Track Bug: 38563
at: gcc.gnu.org/bugzilla
--
Derek M. Jones tel: +44 (0) 1252 520 667
Knowledge Software Ltd mailto:derek@knosof.co.uk
Source code analysis http://www.knosof.co.uk
next prev parent reply other threads:[~2008-12-18 1:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-17 20:05 [PATCH 2/15 v2] Unhardcode byte size being 8 bits Alexey Zaytsev
2008-12-17 23:33 ` David Given
2008-12-18 0:33 ` Alexey Zaytsev
2008-12-18 0:58 ` David Given
2008-12-18 1:24 ` Alexey Zaytsev
2008-12-18 1:10 ` Derek M Jones [this message]
2008-12-18 1:52 ` Derek M Jones
2008-12-18 3:11 ` Alexey Zaytsev
2008-12-18 13:05 ` Derek M Jones
2008-12-18 17:07 ` Alexey Zaytsev
2008-12-18 17:12 ` David Given
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=4949A306.2060200@knosof.co.uk \
--to=derek@knosof.co.uk \
--cc=alexey.zaytsev@gmail.com \
--cc=dg@cowlark.com \
--cc=josh@kernel.org \
--cc=linux-sparse@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.