From: Steve Kenton <skenton@ou.edu>
To: Linux-Kbuild <linux-kbuild@vger.kernel.org>
Subject: Can this type-punned warning be silenced by using a union instead of a cast?
Date: Sat, 27 Dec 2008 21:27:22 -0600 [thread overview]
Message-ID: <4956F21A.108@ou.edu> (raw)
[-- Attachment #1: Type: text/plain, Size: 541 bytes --]
Can this type-punned warning be silenced by using a union instead of a cast?
HOSTCC scripts/basic/fixdep
scripts/basic/fixdep.c: In function 'traps':
scripts/basic/fixdep.c:377: warning: dereferencing type-punned pointer
will break strict-aliasing rules
Something like the attached? As far as I can tell the union should take care of the alignment and make the __attribute__ unnecessary, in which case it does not need to be static either. Compiled with gcc 4.4 cross compiler for i386 successfully but not boot tested.
Steve Kenton
[-- Attachment #2: fixdep.c.patch --]
[-- Type: text/plain, Size: 529 bytes --]
--- linux-2.6/scripts/basic/fixdep.c.orig 2008-12-27 20:54:32.234375000 -0600
+++ linux-2.6/scripts/basic/fixdep.c 2008-12-27 21:03:00.140625000 -0600
@@ -372,11 +372,11 @@ void print_deps(void)
void traps(void)
{
- static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
+ union { int i; char c[4]; } test = { .c = "CONF" };
- if (*(int *)test != INT_CONF) {
+ if (test.i != INT_CONF) {
fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
- *(int *)test);
+ test.i);
exit(2);
}
}
reply other threads:[~2008-12-28 3:54 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4956F21A.108@ou.edu \
--to=skenton@ou.edu \
--cc=linux-kbuild@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.