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?

5
  • If you're asking something about specific standard quotes, tagging with both C and C++ isn't really helpful. For C: aligned is defined. Commented Jul 18, 2014 at 18:23
  • Look here: stackoverflow.com/questions/8752546/… Commented Jul 18, 2014 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? Commented Jul 18, 2014 at 18:24
  • @Deduplicator where is suitable alignment definition there? Commented Jul 18, 2014 at 18:29
  • What exactly is an aligned pointer? Commented Jul 18, 2014 at 18:32

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

alignof(std::max_align_t)=16, but alignof(T*)=8 for any type T.
There is no separate definition of "suitable alignment" That is all what I want to know! Thanks :).
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.

2 Comments

That is, we can delete suitable word from suitable aligned without lost of meaning.
@St.Antario I suppose so, yeah.
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.

2 Comments

It's worth noting that the largest fundamental type on x86/x86_64 is actually long double, which is 10 bytes in size.
In MSVC 32 and 64-bit code, long double maps to double.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.