www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - align number

reply "Katayama Hirofumi MZ" <katayama.hirofumi.mz gmail.com> writes:
version(Win64) {
const int align_number = 8;
} else {
const int align_number = 4;
}

align(align_number):

...long code...
Jun 07 2012
next sibling parent reply "Bernard Helyer" <b.helyer gmail.com> writes:
On Friday, 8 June 2012 at 01:46:15 UTC, Katayama Hirofumi MZ 
wrote:
 version(Win64) {
 const int align_number = 8;
 } else {
 const int align_number = 4;
 }

 align(align_number):

 ...long code...

align(size_t.sizeof); ?
Jun 07 2012
parent reply Denis Shelomovskij <verylonglogin.reg gmail.com> writes:
08.06.2012 7:31, Andrej Mitrovic написал:
 On 6/8/12, Bernard Helyer<b.helyer gmail.com>  wrote:
 Well that doesn't seem to work.

Try this: version(Win64) { align(8): } else { align(4): }

This will not work as you expect. Just like --- version(v1) { class } else { struct } S { int i; } --- will not compile. It's D and there is no C preprocessor: --- version(Win64) { align(8): ... aligned 8 ... } else { align(4): ... aligned 4 ... } ... default aligned ... --- -- Денис В. Шеломовский Denis V. Shelomovskij
Jun 07 2012
parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 08.06.2012 23:16, Kagamin wrote:
 template Aligned(alias Content)
 {
 static if(size_t.sizeof==4)
 align(4) struct Aligned{ mixin Content; }
 else
 align(8) struct Aligned{ mixin Content; }
 }

Ain't structs aligned on word boundary by default? -- Dmitry Olshansky
Jun 08 2012
prev sibling next sibling parent "Bernard Helyer" <b.helyer gmail.com> writes:
On Friday, 8 June 2012 at 02:51:57 UTC, Bernard Helyer wrote:
 On Friday, 8 June 2012 at 01:46:15 UTC, Katayama Hirofumi MZ 
 wrote:
 version(Win64) {
 const int align_number = 8;
 } else {
 const int align_number = 4;
 }

 align(align_number):

 ...long code...

align(size_t.sizeof); ?

Well that doesn't seem to work.
Jun 07 2012
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 6/8/12, Bernard Helyer <b.helyer gmail.com> wrote:
 Well that doesn't seem to work.

Try this: version(Win64) { align(8): } else { align(4): }
Jun 07 2012
prev sibling next sibling parent "Katayama Hirofumi MZ" <katayama.hirofumi.mz gmail.com> writes:
On Friday, 8 June 2012 at 04:16:18 UTC, Denis Shelomovskij wrote:
 It's D and there is no C preprocessor:
 ---
 version(Win64) {
   align(8):
   ... aligned 8 ...
 } else {
   align(4):
   ... aligned 4 ...
 }
 ... default aligned ...
 ---

The code overlaps and it is not much smart.
Jun 07 2012
prev sibling next sibling parent "Kagamin" <spam here.lot> writes:
template Aligned(alias Content)
{
  static if(size_t.sizeof==4)
   align(4) struct Aligned{ mixin Content; }
  else
   align(8) struct Aligned{ mixin Content; }
}
Jun 08 2012
prev sibling next sibling parent "Katayama Hirofumi MZ" <katayama.hirofumi.mz gmail.com> writes:
version(Win64) {
     private const const_align = 8;
} else {
     private const const_align = 1;
}
align(const_align):
...long code...

Please support me!!  Please, please!
Jun 27 2012
prev sibling parent "Katayama Hirofumi MZ" <katayama.hirofumi.mz gmail.com> writes:
private template Aligned() {
     ...long code...
}

version(Win64) {
     align(8): mixin Aligned!();
} else {
     align(1): mixin Aligned!();
}

---END of THREAD---
Aug 03 2012