linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: David Laight <David.Laight@ACULAB.COM>
Cc: linuxppc-dev@lists.ozlabs.org, linux-usb@vger.kernel.org,
	Tabi Timur-B04825 <B04825@freescale.com>,
	Xie Shaohui-B21989 <B21989@freescale.com>
Subject: Re: [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap
Date: Thu, 3 Nov 2011 23:08:18 +0100	[thread overview]
Message-ID: <56B53DA2-CB5E-4EB9-A5B3-470B7B0CD0FD@kernel.crashing.org> (raw)
In-Reply-To: <AE90C24D6B3A694183C094C60CF0A2F6D8AEA4@saturn3.aculab.com>

> Arithmetic on 'void *' should not be done. I know some versions of
> gcc allow it (provided some warning level/option is enabled) but
> that doesn't mean it is valid.

All relevant GCC versions support it (going back to 2.x at least).
It is _always_ allowed, whatever compiler options you use; -pedantic
or -Wpointer-arith will warn (which you can upgrade to an error).

The Linux kernel is not built with these warnings enabled.

>> A char* is incorrect because a char could be more
>> than one byte, in theory.
>
> It is somewhat difficult to untangle the standard, but
> sizeof (char) is defined to be one.

A char takes exactly one byte.  A byte could be more than eight bits,
of course.

In GCC, sizeof(void) is 1 as well.

> Of course, the C language doesn't actually require that
> you can converts between pointers to different types in
> any well-defined manner.

It does actually, see 6.3.2.3/7.  You can convert any pointer to object
to a pointer to a different object type, as long as it is properly  
aligned.
You cannot in general access the object as that new type of course, but
it is perfectly well-defined; in particular, you can convert it back to
the original type and get the same value again, and you can walk  
consecutive
bytes of the object by using a pointer to character type.


Segher

      parent reply	other threads:[~2011-11-03 22:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-03  9:58 [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap Shaohui Xie
2011-11-03 11:14 ` David Laight
2011-11-03 11:38 ` Tabi Timur-B04825
2011-11-03 11:38   ` David Laight
2011-11-03 12:07     ` Tabi Timur-B04825
2011-11-03 12:16       ` David Laight
2011-11-03 14:12         ` Timur Tabi
2011-11-03 22:08         ` Segher Boessenkool [this message]

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=56B53DA2-CB5E-4EB9-A5B3-470B7B0CD0FD@kernel.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=B04825@freescale.com \
    --cc=B21989@freescale.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=linux-usb@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.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 NNTP newsgroup(s).