2

I not understood suitable pointer alignment concept:

There are no constraints on the contents of the allocated storage on return from the allocation function. The order, contiguity, and initial value of storage allocated by successive calls to an allocation function are unspecified. The pointer returned shall be suitably aligned so that it can be converted to a pointer of any complete object type with a fundamental alignment requirement (3.11) and then used to access the object or array in the storage allocated (until the storage is explicitly deallocated by a call to a corresponding deallocation function).

There is no definition of suitable alignment in the sec.3.11. You explain that should mean?

St.Antario
  • 26,175
  • 41
  • 130
  • 318
  • If you're asking something about specific standard quotes, tagging with both C and C++ isn't really helpful. For C: _aligned_ is defined. – mafso Jul 18 '14 at 18:23
  • Look here: http://stackoverflow.com/questions/8752546/how-does-malloc-understand-alignment – mafso Jul 18 '14 at 18:24
  • You're jumping down a rabbit hole here. This question is not easily answered without producing a wall of text. Additionally, it is fairly unusual for most programmers to need to understand it. Some context might help us. Why do you want to know what alignment is? – John Dibling Jul 18 '14 at 18:24
  • @Deduplicator where is suitable alignment definition there? – St.Antario Jul 18 '14 at 18:29
  • [What exactly is an aligned pointer?](http://stackoverflow.com/questions/4322926/what-exactly-is-an-aligned-pointer) – Deduplicator Jul 18 '14 at 18:32

3 Answers3

3

§3.11/1 says,

Object types have alignment requirements (3.9.1, 3.9.2) which place restrictions on the addresses at which an object of that type may be allocated.

So if a pointer is "suitably aligned" it means that the address represented by the pointer satisfies these restrictions. What exactly this means for the numerical value of the address is implementation-defined.

Brian Bi
  • 111,498
  • 10
  • 176
  • 312
3

This means that for any complete object type with a fundamental alignment, it should be possible to convert the pointer returned to a pointer to that object type, respecting the alignment requirement of that object type.

In practice, since alignments are powers of two, this means that an allocation function is required to return a pointer aligned to alignof(std::max_align_t).

There is no separate definition of "suitable alignment"; in this paragraph as elsewhere "suitably" just means that there is a requirement which the program is required to satisfy for the rest of the paragraph to hold.

ecatmur
  • 152,476
  • 27
  • 293
  • 366
2

Alignment is defined by the OS and platform. Usually it is the size of the largest basic type (a pointer or double), but it could be more. For instance, on Windows, x86 is 8 byte and x64 is 16 byte.

Khouri Giordano
  • 1,426
  • 15
  • 17