Re: Pointer arithmetic error

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

 



On Fre, 2008-06-27 at 11:55 +0100, David Given wrote:
> Bernd Petrovitsch wrote:
> [...]
> > In C, there is no type "byte" (unless you typedef oder #define it).
> > "byte" is usually (but not necessarily) meant as "unsigned char".
> 
> The issue here is that sparse is helpful and converts pointer offsets 
> into byte offsets when generating code for pointer arithmetic. So:
> 
> const int* p = (const char*) 1234;
> p += 10;
> 
> -->
> 
> set.32 %p0 <- 1234
> add.32 %p1 <- %p0, 40
> (In fact, in this example it'd collapse these together and use 1274 
> instead.)
> 
> This appears to be done using hard-coded knowledge that a byte (one unit 
> of addressingness) is 8 bits wide.

It is done IMHO with the false knowledge that "sizeof(int) == 4 *
sizeof(char)".
IIUC your hardware (a DSP or what is it exactly) has "sizeof(int) ==
sizeof(char)" so the size of a char (or int) as such is irrelevant.

> Chris Li wrote:
> > Byte need to big enough to hold the char. Using bits_in_byte is better.
> > There might be other place in sparse assume byte is 8 bits.
> 
> IIRC C specifies that sizeof() returns values measured in chars, but I 

ACK. Therefore "sizeof(char) == 1" must always hold.

> don't believe it specifies any mapping between the size of chars and the 
> underlying addressing units --- it should be possible to use 16-bit 

Yes, that's what CHAR_BIT is for.

> chars, for example, on an 8-bit byte system. Using 32-bit ints, 
> sizeof(int) would then return 2; but you wouldn't be able to access 
> individual bytes from C.

ACK (apart from "shift and mask it" ans similar).

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services


--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux