[ create a new paste ] login | about

Link: http://codepad.org/rGnAdZem    [ raw code | output | fork ]

C++, pasted on May 22:
#include <cstddef>
#include <cassert>

template<int size>
class Padding {
    char padding[size];
};
//User can't do _anything_ with this type
//except make it, copy it, and destruct it.

struct Name {
    long Id;
    Padding<32> padding; 
    float X;
};

int main() {
  assert(sizeof(int) == 4);
  assert(sizeof(long) == 4);
  assert(sizeof(float) == 4);
  assert(offsetof(Name, Id) == 0);
  assert(offsetof(Name, X) == 0x24);
    Name a;
}


Output:
1
2
3
4
5
6
cc1plus: warnings being treated as errors
In function 'int main()':
Line 21: warning: invalid access to non-static data member 'Name::Id' of NULL object
Line 21: warning: (perhaps the 'offsetof' macro was used incorrectly)
Line 22: warning: invalid access to non-static data member 'Name::X' of NULL object
Line 22: warning: (perhaps the 'offsetof' macro was used incorrectly)


Create a new paste based on this one


Comments: