r/cpp_questions • • Aug 31 '25

OPEN What is long long

I saw some c++ code and I noticed it has long long, I never knew you could put 2 primitives next to each other. What does this do?

1 Upvotes

37 comments sorted by

35

u/ddxAidan Aug 31 '25

“Long long” is a primitive itself, but its exact meaning could depend. It is at least 64 bits

13

u/hwc Aug 31 '25

it is often the "underlying" type of an int64_t. but if you want a 64 bit int, include <cstdint> and use int64_t!

6

u/MarcoGreek Aug 31 '25

int64_t is long under Linux. And long is not long long. So you can call different overloads. So if you use code which is not using the aliases you can get into trouble.

3

u/ddxAidan Aug 31 '25

Agreed - to be platform agnostic, everyone would do well to use cstdint

3

u/bert8128 Aug 31 '25

It if you are communicating between different platforms then sending a int64 from one might not be received in the same way as the other. Eg you might send a long, but receive a long long. This can have negative consequences.

13

u/y53rw Aug 31 '25 edited Aug 31 '25

All of the fundamental types are here.

https://en.cppreference.com/w/cpp/language/types.html

Note that some types can be written multiple ways. long long can also be written long long int or signed long long int or signed long long.

7

u/Warshrimp Aug 31 '25

Wouldn't it be great if char = 8, short = 16, int = 32, long = 64 and long long were 128? I hope the next time someone treats a new data model they stick with this.

7

u/no-sig-available Aug 31 '25

Wouldn't it be great if 

We have had systems with char = 9, short = 18, int = 36, and long long = 72. The standard didn't want to ban those.

https://stackoverflow.com/questions/6971886/exotic-architectures-the-standards-committees-care-about

You can add static_assert for you code, so it will fail to compile on such systems (because it would probably not work anyway). Or use int32_t, which has the same effect (fail to compile when it doesn't exist).

1

u/DrShocker Sep 01 '25

Or if you don't want to fail to compile there's the fast or least versions that help the compiler pick what number to use in a way that respects the properties you need

19

u/y53rw Aug 31 '25

I would prefer just go with the naming scheme used by Rust and other modern systems languages. i8, u8, i16, u16, etc... And then isize/usize for the pointer sized integers.

7

u/ChickenSpaceProgram Aug 31 '25

just use the stdint.h types

5

u/KeretapiSongsang Aug 31 '25

There are multiple CPU and OS architectures. To each their own set of data width/length.

Fixed data length definition like that is usually available in trans piled/LLVM/JIT languages where the "compilers" or "interpreters" has the control of the data types.

2

u/BSModder Aug 31 '25 edited Aug 31 '25

long is usual 32.

I propose this naming scheme

short = 16, long = 32, short short = 8, long long = 64.

This can be extended to cover all sizes, want a 128 bits type? long long long. 4 bits type? short short short. 24 bits? short long. 21? short long short long short

7

u/y53rw Aug 31 '25

short short short short short = bool

5

u/WildCard65 Aug 31 '25

Long has different sizes between Windows and Linux. Windows its 32 bits while 64bit Linux its 64 bits.

1

u/no-sig-available Aug 31 '25

Long has different sizes between Windows and Linux. 

Yes, Windows is consistent, and has had 32-bit long all the way since 16-bit Windows. :-)

Linux found it a good idea to add long long, and then make long the same size?

3

u/Vazumongr Aug 31 '25

Man, I just prefer int8, int16, int32, int64 tbh. All the information regarding the type right in the name.

edit: uint8, uint16, uint32, and uint64 for unsigned ints too :>

5

u/BSModder Aug 31 '25

My comment was satire. I don't think any language should use it ever.

IntN system is probably the best for clarity.

2

u/Vazumongr Aug 31 '25

Somehow I didn't get that. Oops.

1

u/SoerenNissen Aug 31 '25

Depending on whether the system models unsigned types, I either prefer

  • I8

  • I16

  • etc./ (for a system that doesn't model unsigned)

or

  • S8/U8

  • S16/U16

  • etc./ (for a system that models a difference between signed/unsigned)

3

u/SoerenNissen Aug 31 '25

I suggest a log scale centered on 32 bit.

  • sizeof(Im2) == 1

  • sizeof(Im1) == 2

  • sizeof(I) == 4 with alias types I0, Im0 and Ip0

  • sizeof(Ip1) == 8

  • sizeof(Ip2) == 16

1

u/DrShocker Aug 31 '25

In my opinion, char and uint8 shouldn't be considered synonyms since the kinds of operations you want to do with a byte or an 8 bit integer might reasonably be wrong if they get mix.

2

u/TomDuhamel Aug 31 '25

I don't disagree. The relationship is logistical unfortunately.

1

u/heyheyhey27 Sep 02 '25

C++ goes out of its way to support odd architectures, including ones that don't do 8 bits per byte and ones that only have 7-bit chars limiting their character set.

1

u/GLvoid Aug 31 '25

What about a short long int? Is that even a valid type?

2

u/jedwardsol Aug 31 '25

or long int signed long

0

u/no-sig-available Aug 31 '25

Note that some types can be written multiple ways. long long can also be written long long int or signed long long int or signed long long.

Or, if you want to go all the way, long signed int long also works. :-)

The rules just say that the words can be combined, but the order isn't specified. You can also add const, volatile, or typedef anywhere in the soup.

1

u/tangerinelion Sep 01 '25

Sure, class loong { static constexpr inline volatile long const signed int long x = 0; };. Beautiful.

7

u/DrShocker Aug 31 '25

You can see the list of integegral types here:

https://en.cppreference.com/w/cpp/language/types.html#Integral_types

Note: the exact meaning of some of them is platform dependent. So, generally it's suggested you use the ones defined with the width in their name since it's more clear and portable. (std::int64_t for example)

https://en.cppreference.com/w/cpp/header/cstdint.html

4

u/eslibedesh0116 Aug 31 '25

It's not just a long, it's a loooooonnnggggg long. (it has more bits)

2

u/SmokeMuch7356 Aug 31 '25 edited Aug 31 '25

It designates an integer type that's at least as wide as a long but could be wider. For example, if someone builds an 80-bit architecture,1 an int could be 32 bits, long 64 bits, and long long 80 bits.

6.8.2 Fundamental types [basic.fundamental]
1 There are five standard signed integer types “signed char”, “short int”, “int”, “long int”, and “long long int”. In this list, each type provides at least as much storage as those preceding it in the list. There may also be implementation-defined extended signed integer types. The standard and extended signed integer types are collectively called signed integer types. The range of representable values for a signed integer type is −2N-1 to 2N−1 − 1 (inclusive), where N is called the width of the type.

Latest working draft of the C++ standard.

See also section 9.2.9.1 on type specifiers. The language grammar allows arbitrary combinations of type specifiers, but there are additional semantic rules that only allow certain combinations:

  • (2.1) const can be combined with any type specifier except itself.

  • (2.2) volatile can be combined with any type specifier except itself.

  • (2.3) signed or unsigned can be combined with char, long, short, or int.

  • (2.4) short or long can be combined with int.

  • (2.5) long can be combined with double.

  • (2.6) long can be combined with long.


  1. Powers of 2 are convenient but not necessary.

1

u/wigglytails Aug 31 '25

There should be longer long

1

u/dan-stromberg Aug 31 '25

I'm not sure if you mean that literally (like "longer long i;") or if you want a wider type in C++. But C++23 has one, and g++ and clang both have __int128.

1

u/[deleted] Aug 31 '25

Its a type int but it has more bit thn int Example int has 16 bits but if you get a bigger value which can’t be dealt by int you can use long long or long which is 64 & 32 bits.

1

u/Plastic_Fig9225 Aug 31 '25

People with complexes use long long to hold their boolean values.