Saturday, February 11, 2012

A Random Post: Am I on a 32- or 64-bit OS?

So in response to a question on IRC this morning (and it's early and I'm not fully awake), here's a quick program I wrote to show how to detect if you're on a 16-, 32-, or 64- bit OS by checking the size of an int* in C/C++:

#include <iostream>


int main (int argc, char* argv[])
{
  int foo = sizeof(int*);
  
  switch (foo)
  {
  case 2:
    std::cout << "Size = 2: 16 bit OS" << std::endl;
    break;
  case 4:
    std::cout << "Size = 4: 32 bit OS" << std::endl;
    break;
  case 8:
    std::cout << "Size = 8: 64 bit OS" << std::endl;
    break;
  default:
    std::cout << "Size = " << foo << std::endl;
  }


  return(0);
}

No comments:

Post a Comment