www.digitalmars.com         C & C++   DMDScript  

c++ - custom alignment (__declspec(align))

reply Alexander <sergeyn funcom.com> writes:
Hello,

Is there a way to specify custom alignment for structures and variables, 
something like __declspec(align(<alignment>)) ?

Thanks.
Jan 24 2009
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Alexander wrote:
 Is there a way to specify custom alignment for structures and variables, 
 something like __declspec(align(<alignment>)) ?
http://www.digitalmars.com/ctg/pragmas.html#pack
Jan 24 2009
parent reply Sergey <sergeyn funcom.com> writes:
As far as I understood the documentation this pragma sets alignment for 
members only, but not instances of that struct or class. For example, 
how would I declare an int variable, which would appear at 128 byte 
aligned address ?

Thanks.

Walter Bright wrote:
 Alexander wrote:
 Is there a way to specify custom alignment for structures and 
 variables, something like __declspec(align(<alignment>)) ?
http://www.digitalmars.com/ctg/pragmas.html#pack
Jan 26 2009
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Sergey wrote:
 As far as I understood the documentation this pragma sets alignment for 
 members only, but not instances of that struct or class. For example, 
 how would I declare an int variable, which would appear at 128 byte 
 aligned address ?
There's currently no way to do it statically, as segments themselves are aligned on 16 byte boundaries. You could do it dynamically by allocating a chunk of memory and picking a 128 byte aligned piece of it.
Jan 26 2009
parent reply Sergey <sergeyn funcom.com> writes:
Walter Bright wrote:
 Sergey wrote:
 As far as I understood the documentation this pragma sets alignment 
 for members only, but not instances of that struct or class. For 
 example, how would I declare an int variable, which would appear at 
 128 byte aligned address ?
There's currently no way to do it statically, as segments themselves are aligned on 16 byte boundaries. You could do it dynamically by allocating a chunk of memory and picking a 128 byte aligned piece of it.
Is it in the plans to get that fixed ? Thanks, Sergey.
Jan 27 2009
parent reply Cesar Rabak <crabak acm.org> writes:
Sergey escreveu:
 Walter Bright wrote:
 Sergey wrote:
 As far as I understood the documentation this pragma sets alignment 
 for members only, but not instances of that struct or class. For 
 example, how would I declare an int variable, which would appear at 
 128 byte aligned address ?
There's currently no way to do it statically, as segments themselves are aligned on 16 byte boundaries. You could do it dynamically by allocating a chunk of memory and picking a 128 byte aligned piece of it.
Is it in the plans to get that fixed ? Thanks, Sergey.
Just for a better grasp on the issue: why is there any need to "fix" such a thing? IMNHO this is not a fault or defect of the compiler, or is it?
Jan 27 2009
parent reply Sergey <sergeyn funcom.com> writes:
 IMNHO this is not a fault or defect of the compiler, or is it?
Well, yes, sorry for putting it wrong, Anyway, Is this feature going to be implemented any time soon ? Thanks. Cesar Rabak wrote:
 Sergey escreveu:
 Walter Bright wrote:
 Sergey wrote:
 As far as I understood the documentation this pragma sets alignment 
 for members only, but not instances of that struct or class. For 
 example, how would I declare an int variable, which would appear at 
 128 byte aligned address ?
There's currently no way to do it statically, as segments themselves are aligned on 16 byte boundaries. You could do it dynamically by allocating a chunk of memory and picking a 128 byte aligned piece of it.
Is it in the plans to get that fixed ? Thanks, Sergey.
Just for a better grasp on the issue: why is there any need to "fix" such a thing? IMNHO this is not a fault or defect of the compiler, or is it?
Jan 28 2009
parent Walter Bright <newshound1 digitalmars.com> writes:
Sergey wrote:
 Is this feature going to be implemented any time soon ?
Not in the near future.
Mar 05 2009