Re: linux/kernel.h (&_x == &_y); why

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 05, 2003 at 12:31:40 +0200, Momchil Velikov wrote:
> >>>>> "Jan" == Jan Hudec <bulb@ucw.cz> writes:
> 
> Jan> On Tue, Dec 02, 2003 at 15:12:52 -0800, John Tyner wrote:
> >> I believe that it is so that gcc will throw a warning if the two types 
> >> are not compatible.
> 
> Jan> Actualy, it should throw a warning if they are not exactly the same,
> Jan> because if they are not, the comparsion breaks aliasing rules.
> Jan> Especially it should throw a warning if one is signed and the other is
> Jan> not.

Well, I've just checked what the warning will actually look like:

,test.c: In function `foo':
,test.c:3: warning: comparison of distinct pointer types lacks a cast

(the pointer were signed ** and unsinged ** and that are definitely
compatible).

> Aliasing rules are NOT like this.  See below:
> 
> [#7] An object shall have its stored value accessed only by an lvalue
>      expression that has one of the following types:73)
> 
>   -- a type compatible with the effective type of the object,
>
>   -- a qualified version of a type compatible with the effective type
>      of the object,
> 
>   -- a type that is the signed or unsigned type corresponding to the
>      effective type of the object,
> 
>   -- a type that is the signed or unsigned type corresponding to a
>      qualified version of the effective type of the object,
> 
>   -- an aggregate or union type that includes one of the
>      aforementioned types among its members (including, recursively, a
>      member of a subaggregate or contained union), or
> 
>   -- a character type.

Well, right. signed and unsigned variants can alias and character can
alias anything. However, the warning is fortunately generated on exact
equality (of efective types).

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux