-1

Values a and b have same output:

int a = 0xEFEFEFEF;
long b = 0xEFEFEFEF;
cout << a << endl << b << endl; 

I heard that a long type has more processing time to calculation because long should be cast to int for calculation. Is int really faster then long?

Eitan T
  • 32,660
  • 14
  • 72
  • 109
user1448323
  • 159
  • 1
  • 3
  • 7
  • 4
    What `int` and `long` actually mean is compiler specific. Perhaps you could tell us which compiler you are using, and the system architecture you are targetting? – Rook Jun 22 '12 at 13:48
  • 1
    All C integral types depend on the platform (i.e. CPU and compiler). Your question cannot be answered in general without stating the platform. – thiton Jun 22 '12 at 13:49
  • Possible duplicate: http://stackoverflow.com/questions/900230/difference-in-long-vs-int-data-types-in-c – Joel Rondeau Jun 22 '12 at 13:52

1 Answers1

5

This question is impossible to answer universally in a sense whether long is faster than int.

The code could be ran on a 16-bit platform with 32-bit long and 16-bit int on which the int would probably be faster - but not necessarily. On the other hand, on a native 32-bit platform which has 32-bitint and 64-bit long, the long could be faster - but not necessarily.

So it is platform dependent, and compiler dependent. The bottom line is that usually the operations on target CPU's native word length types are no slower(usually faster) than the operations which may require casting the width to native size.

zxcdw
  • 1,629
  • 1
  • 10
  • 18