Crazy Chenz
Crazy Chenz

Reputation: 13208

Why might using a "long long" in C or C++ be a bad thing?

Why might using a "long long" in C or C++ be a bad thing?

I was compiling a runtime library the other day and in the code it checks to see if longs are 64bits and if not it uses a long long. But along with that, it sends out a #warning "using long long". I can't think of any reason for the "long long" being a warning unless it was leftover debug cruft from the developer.

Thanks Chenz

Upvotes: 4

Views: 767

Answers (4)

user50049
user50049

Reputation:

I agree with Thomas Padron-McCarth. It is much better to check for the existence of int64_t (signed) or uint64_t (unsigned) respectively, and use them if they exist. It's the same sort of sanity that led to size_t.

Upvotes: 7

Peeter Joot
Peeter Joot

Reputation: 8260

It isn't portable. Specifically, the windows compiler didn't use to support long long, and you had to use __int64 and unsigned __int64 instead (but couldn't use necessarily use on non-windows platforms).

This was a while ago, so perhaps now there is a better chance of always having uint64_t and int64_t available.

Upvotes: 5

UncleBens
UncleBens

Reputation: 41351

As far as I know, long long is currently standard only in C99. It will also be a type in C++0x, but most modern compilers should support it already.

However, for fixed-sized integers one might use the C99 header <stdint.h>, or in C++ <boost/cstdint.hpp>

Upvotes: 10

Thomas Padron-McCarthy
Thomas Padron-McCarthy

Reputation: 27652

Two reasons:

You don't know how long (haha!) a long long is, so if the code assumes that it is exactly 64 bits, there could be a problem.

If you use an old C compiler, it might not support long long.

Upvotes: 9

Related Questions