Re: Show me the mis-alignment.
On Dec 6, 4:13 am, Jeff?Relf <Jeff_R...@Yahoo.COM> wrote:
Given VC++ 8.0 without so-called ? optimizations ? or packing rules,
You can't show me a __int64 static, local or const
that isn't aligned on an 8-byte-boundry. I rest my case.
aligne.cc:
#include <iostream>
double two_pi = 6.28 ;
void
f( long ifreq )
{
__int64 w = two_pi * ifreq ;
std::cout << &w << std::endl ;
}
void
g()
{
f( 20 ) ;
}
template< size_t N >
void
h()
{
char dummy[ N ] ;
f( 20 ) ;
}
template< size_t N >
void
i()
{
char dummy[ N ] ;
__int64 w ;
std::cout << &w << std::endl ;
}
int
main()
{
f( 20 ) ;
g() ;
h< 1 >() ;
h< 2 >() ;
h< 3 >() ;
h< 4 >() ;
h< 5 >() ;
h< 6 >() ;
h< 7 >() ;
h< 8 >() ;
i< 1 >() ;
i< 2 >() ;
i< 3 >() ;
i< 4 >() ;
i< 5 >() ;
i< 6 >() ;
i< 7 >() ;
i< 8 >() ;
return 0 ;
}
Compiled with:
cl /vmg /GR /Gy /EHs /J /nologo /D_CRT_SECURE_NO_DEPRECATE /MTd /
GS- /Zi /w /D_DEBUG align.cc
Output:
0012FF40
0012FF38
0012FF34
0012FF34
0012FF34
0012FF34
0012FF30
0012FF30
0012FF30
0012FF30
0012FF44
0012FF44
0012FF44
0012FF44
0012FF44
0012FF44
0012FF44
0012FF44
Note that the original question concerned double, and this is
just a quick edit of the program which I used to verify that
VC++ doesn't guarantee alignment of double. I don't know why
the discussion changed type---double is C++, __int64 isn't, and
VC++ is the only compiler at my disposition which will compile
the above. The fact remains that VC++ doesn't guarantee
alignment of more than 4, ever.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34