"abir" <> wrote in message
news:ebe0739d-fee8-4eac-8703-...
[...]
You can usually get the alignment of a type like:
__________________________________________________ ______________________
#include <iostream>
#include <cstddef>
template<typename T>
static std::size_t
align_of() {
struct align_of_aligner {
char m_pad;
T m_obj;
};
return offsetof(align_of_aligner, m_obj);
}
struct foo {
char c;
double a;
};
int main(void) {
std::cout << "align_of<char>() == " << align_of<char>() << std::endl;
std::cout << "align_of<short>() == " << align_of<short>() << std::endl;
std::cout << "align_of<int>() == " << align_of<int>() << std::endl;
std::cout << "align_of<long>() == " << align_of<long>() << std::endl;
std::cout << "align_of<float>() == " << align_of<float>() << std::endl;
std::cout << "align_of<double>() == " << align_of<double>() << std::endl;
std::cout << "align_of<long double>() == " << align_of<long double>() <<
std::endl;
std::cout << "align_of<struct foo>() == " << align_of<foo>() << std::endl;
return 0;
}
__________________________________________________ ______________________
You can also forcefully align addresses by using the following simplistic
HACK:
http://groups.google.com/group/comp....b1cac59c8e98a3
(read all, follow links...)