Re: This code, similar to yours, GLChin:
? main() { const double w = 0 ; } ?,
The address of ? w ? is 8-byte-aligned.
Using VC++ 8, you can check for yourself,
You can check whether it is 8 byte aligned in one particular
case, after whatever calls preceded it.
#pragma warning( disable: 4007 4189 4430 4508 )
WinMain( int, int, int, int ) {
const __int32 Int32 = 0 ; const __int64 Int64 = 0 ;
int Implicit_Size_of_Int32 = int( & Int64 ) - int( & Int32 );
// Breaking here, ? Implicit_Size_of_Int32 == 8 ?.
}
I'm not sure what that's supposed to check. It's not C++, so it
doesn't tell us anything about what C++ does. And I don't see
how it would be related to how VC++ would lay out a double.
FWIW: VC++ doesn't guarantee 8 byte alignment. All of my
compilers on Sparc do---perhaps because accessing a double at an
address which isn't 8 byte aligned will cause a core dump
.
Curiously, g++ on both the Linux machine and the Windows
machines here (32 bit Intel) also seems to guarantee 8 byte
alignment.
You might try something like the following:
#include <iostream>
double two_pi = 6.28 ;
void
f( long ifreq )
{
double 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 ] ;
double 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 ;
}
If all of the addresses output are multiples of 8, it still
isn't guaranteed, but I'd guess that there is a very good chance
of it being true. If they aren't, of course, you know that it
isn't guaranteed.