Re: which way is faster?

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

 



On Tue, 2006-12-19 at 18:00 +0200, Momchil Velikov wrote:
> Ming Zhang wrote:
> > On Tue, 2006-12-19 at 12:56 +0200, Momchil Velikov wrote:
> >> Arjan van de Ven wrote:
> >>> On Mon, 2006-12-18 at 17:12 -0500, Ming Zhang wrote:
> >>>> See this code piece
> >>>>
> >>>> http://lxr.linux.no/source/drivers/scsi/libata-scsi.c?v=2.6.18#L1049
> >>>>
> >>>> 1056         lba |= ((u64)scsicmd[2]) << 24;
> >>>> 1057         lba |= ((u64)scsicmd[3]) << 16;
> >>>> 1058         lba |= ((u64)scsicmd[4]) << 8;
> >>>> 1059         lba |= ((u64)scsicmd[5]);
> >>>>
> >>>> it can also be written as 
> >>>>
> >>>> lba = be32_to_cpu(*(u32 *)(&scsicmd[2])
> >> ISO/IEC 9899:1999(E) "6.5 Expressions" [#7]
> > 
> > read but still can not understand why u list this here.
> 
> Because this code
> 
>    ba = be32_to_cpu(*(u32 *)(&scsicmd[2])
> 
> violates this requirement
> 
>   ISO/IEC 9899:1999(E) "6.5 Expressions" [#7]
> 
> unless you have checked in all callers of ``scsi_10_lba_len'' (and
> transitively in their callers, if necessary) that the first parameter in
> fact does refer to an object of type ``u32'', in which case the above
> code becomes simply non-robust instead of outright non-conforming.
> 

scsicmd is u8*, so scsicmd + 2 is also u8*, why can not cast it to u32*?
u* is a unsigned char so a character type" right?


> ~velco
> 


--
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