[ create a new paste ] login | about

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

C++, pasted on Jun 22:
#include <iostream>
using namespace std;

template <typename T>
int mysizeof()
{
  T temp1;
  T temp2;

  return (int)&temp1 - (int)&temp2;
}

int main()
{
  cout << "sizeof mysizeof" << endl;

  cout << "char: " << mysizeof<char>() << endl;
  cout << "short: " << mysizeof<short>() << endl;
  cout << "int: " << mysizeof<int>() << endl;
  cout << "long: " << mysizeof<long>() << endl;
  cout << "float: " << mysizeof<float>() << endl;
  cout << "double: " << mysizeof<double>() << endl;
  cout << "long double: " << mysizeof<long double>() << endl;
}


Output:
1
2
3
4
5
6
7
8
sizeof mysizeof
char: 1
short: 2
int: 4
long: 4
float: 4
double: 8
long double: 16


Create a new paste based on this one


Comments: