Deqing
Deqing

Reputation: 14632

Comparing long long with 0

long long llIdx = foo();
if (llIdx > 0LL) // Can I use 0 here?
  ...

Is there any problem if I use 0 instead of 0LL in above code?

When should I prefer 0LL over 0?

Upvotes: 8

Views: 24126

Answers (1)

kdopen
kdopen

Reputation: 8205

Yes, you can use a plain 0 here. The compiler would look at the type of each argument to > and promote the smaller one so that they are the same size.

Thus llIdx > 0 and llIdx > 0LL are equivalent.

Upvotes: 12

Related Questions