Re: pointer conversion



Malcolm McLean wrote:

.... snip ...

Arrays have to be contiguous in memory. No padding bytes may be
inserted between items. The rest follows from that.

Nonsense. Consider:

struct foo {int iv; char ch} arr[N];

A struct foo, on a machine with sizeof int == 4, will be occupy 5
bytes. However, in order to make addressable arrays of these,
sizeof struct foo == 8 (assuming ints need to be aligned modulo
4). I.E. there are 3 padding bytes per item.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

.



Relevant Pages

  • Re: Code speedup
    ... >>Your intuition can often be wrong... ... > statically-sized arrays to be allocated adjacently, ... Cache-tag addresses for Aare ... padding the J-dimension of A may change this behavior ...
    (comp.lang.fortran)
  • Re: byte order
    ... casting objects to arrays of bytes, and guarantees that such an array ... The standard also gives the possibility of integer types containing ... padding bits, and it is not specified how such bits can be detected. ... code that cares about endianness, so it's not really an issue. ...
    (comp.lang.lisp)
  • Re: byte order
    ... casting objects to arrays of bytes, and guarantees that such an array ... The standard also gives the possibility of integer types containing ... padding bits, and it is not specified how such bits can be detected. ... Bound variables, free programmers. ...
    (comp.lang.lisp)
  • Re: multidimensional arrays and cute tricks
    ... >>now you can see that the memcpy was originally tried, ... C has arrays whose elements are in turn arrays. ... > struct, and that struct would need padding between adjacent array ... the padding must be part of the struct type. ...
    (comp.lang.c)