Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #59538

Re: Alignment requirement of basic types

From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.lang.c
Subject Re: Alignment requirement of basic types
Date 2015-04-03 18:40 +0000
Organization Aioe.org NNTP Server
Message-ID <20150403112053.496@kylheku.com> (permalink)
References <mfm5mg$4rp$1@dont-email.me> <551EB3B9.7090206@verizon.net> <slrnmhtj1m.gus.usenet@xargs-spam.com> <551ED1A1.8090009@verizon.net>

Show all headers | View raw


On 2015-04-03, James Kuyper <jameskuyper@verizon.net> wrote:
> On 04/03/2015 01:21 PM, John Temples wrote:
>> On 2015-04-03, James Kuyper <jameskuyper@verizon.net> wrote:
>>> C2011 requires that alignments must be powers of 2, no such requirement
>>> existed in earlier versions of the C standard. I've no idea whether
>>> there's ever been an implementation of C where that wasn't the case.
>> 
>> I have used 8-bit platforms with C compilers that supported 24-bit
>> integer and floating point types.  These platforms had no alignment
>> requirements for multi-byte objects, so it was possible to have
>> objects aligned on a three-byte boundary.
>
> The C standard defines "alignment" as a "requirement that objects of a
> particular type be located on storage boundaries with addresses that are
> particular multiples of a byte address" (3.2p1). "No alignment
> requirement" is slightly a misnomer - the correct way to say it is that
> the  alignment requirement is 1, which is a power of 2.

Another view is that an alignment requirement, if it exists, is that
a type be located on storage boundaries which are a product of
some subset of the integer factors of the size of the type (possibly
with a requirement that repeated factors be included as separate
members of the set).

1 is not a factor of any integer; factors start at 2. So if there is no
alignment requirement, the subset of integer factors whose product
is the alignment is empty.

If a number must be put on this situation, then it can be regarded
as an alignment of 1. This agrees with the very useful convention that
the product of an empty set of numbers is 1.

> Having "no alignment requirement" would correspond to allowing the start
> of an object of that type to be anywhere, even an irrational fraction of
> the way between the start of one byte and the start of the next byte. C
> doesn't allow such things. An alignment requirement must be a positive
> integer (since C90) and more specifically, "a non-negative integral
> power of 2" (since C2011 - 6.2.8p4).

An alignment requirement is a requirement which renders certain results of
pointer arithmetic incorrect.

Since no fractional address can be the result of pointer arithmetic,
considering such is moot. If no pointer arithmetic is incorrect on account
of the multiple of the address, then there is no alignment requirement
in effect.

Or, from a slightly different perspective, the smallest addressable unit of
storage is the byte in C. This requirement is independent of anything that
discusses alignment.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Alignment requirement of basic types Noob <root@127.0.0.1> - 2015-04-03 15:48 +0200
  Re: Alignment requirement of basic types Tim Prince <tprince@computer.org> - 2015-04-03 10:23 -0400
  Re: Alignment requirement of basic types James Kuyper <jameskuyper@verizon.net> - 2015-04-03 11:37 -0400
    Re: Alignment requirement of basic types John Temples <usenet@xargs-spam.com> - 2015-04-03 17:21 +0000
      Re: Alignment requirement of basic types James Kuyper <jameskuyper@verizon.net> - 2015-04-03 13:45 -0400
        Re: Alignment requirement of basic types Kaz Kylheku <kaz@kylheku.com> - 2015-04-03 18:40 +0000
      Re: Alignment requirement of basic types Keith Thompson <kst-u@mib.org> - 2015-04-03 10:50 -0700
      Re: Alignment requirement of basic types glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-04-03 19:02 +0000
    Re: Alignment requirement of basic types Kaz Kylheku <kaz@kylheku.com> - 2015-04-03 18:01 +0000
  Re: Alignment requirement of basic types Richard Damon <Richard@Damon-Family.org> - 2015-04-03 12:05 -0400
    Re: Alignment requirement of basic types glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-04-03 16:48 +0000
  Re: Alignment requirement of basic types Kaz Kylheku <kaz@kylheku.com> - 2015-04-03 16:46 +0000
    Re: Alignment requirement of basic types Keith Thompson <kst-u@mib.org> - 2015-04-03 11:06 -0700
      Re: Alignment requirement of basic types Robert Wessel <robertwessel2@yahoo.com> - 2015-04-05 22:22 -0500
  Re: Alignment requirement of basic types Waldek Hebisch <hebisch@antispam.uni.wroc.pl> - 2015-04-04 23:15 +0000

csiph-web