This should work, even with the C style casting
Code:
#include <iostream>
using namespace std;
int main()
{
unsigned variableY;
int variableX;
cout << "\nNote: variableX is a signed int while variableY is an unsigned int";
cout << "\n\nThe size of variableX is: " << sizeof variableX << " bytes";
cout << "\nThe size of variableY is: " << sizeof variableY << " bytes" << endl;
cout << "\nThe address of the memory location of variableX: " << &variableX << endl;
cout << "The address of the memory location of variableY: " << &variableY << endl << endl;
if ((void*)&variableX < (void*)&variableY)
{
if (sizeof(int) == ((long)&variableY - (long)&variableX))
{
cout << "They are next to one another in memory!" << endl;
}
else
{
cout << "They are not adjacent to one another in memory!" << endl;
}
}
else if ((void*)&variableX > (void*)&variableY)
{
if (sizeof(int) == ((long)&variableX - (long)&variableY))
{
cout << "They are next to one another in memory!" << endl;
}
else
{
cout << "They are not adjacent to one another in memory!" << endl;
}
}
return 0;
}
Slackware 13/ArchLinux - C/Assem/Python