CKTIS / C++
long — signed integer type
long is a standard signed integer type with a width of at least 32 bits. The spellings long int and signed long denote the same type. Do not assume, however, that long always has 64 bits or occupies a particular number of bytes.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
long name = 42L;
long int name2 = 42L;
signed long name3 = -42L;
unsigned long name4 = 42UL;long, long int, signed long, and signed long int denote the same signed integer type. unsigned long is a distinct unsigned type; long long is also a distinct type, not another name for long.
The width of long is at least 32 bits but depends on the implementation. It represents at least the values from −2147483648 to 2147483647. Do not assume a particular result for sizeof(long) or that the type is larger than int. Signed arithmetic overflow causes undefined behavior.
The L suffix in 100000L produces a literal of type long here. In general, a decimal literal with L can have type long long if it does not fit in long. In the example, multiplication takes place in long, and the result 300000 fits within its guaranteed range.
The displayed code was run unchanged in an isolated environment, and its standard output exactly matched the stated output. The supplied source is an evolving working draft, not a frozen C++23 publication.
Examples
#include <iostream>
int main() {
long count = 100000L;
long total = count * 3L;
std::cout << total << '\n';
}
Result
300000
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.