Table of Contents
A brief history of integers
The Mystery of Size
Specifications brought by ANSI C (1989)
The current situation of integers
Best Practices
Home Backend Development C++ Integers in C: a little history

Integers in C: a little history

Apr 04, 2025 am 06:09 AM
c language processor ai

Integers in C: a little history

Integers are the most basic data type in programming and can be regarded as the cornerstone of programming. The job of a programmer is to give these numbers meanings. No matter how complex the software is, it ultimately comes down to integer operations, because the processor only understands integers.

To represent negative numbers, we introduced two's complement ; to represent decimal numbers, we created scientific notation, so there are floating-point numbers. But in the final analysis, everything is still inseparable from 0 and 1.


A brief history of integers

In C, int is almost the default type. Although the compiler may issue a warning, in many cases you can still write code like this:

 <code class="c">main(void) { return 0; }</code>
Copy after login

From a technical point of view, this is equivalent to the following code:

 <code class="c">int main(void) { return 0; }</code>
Copy after login

This practice stems from the programming habit at that time: if the programmer does not specify a type, it is reasonable to use integers by default.

This is also considered in the original intention of the C language design. Initially, int did not have a standard size. On the PDP-11 processor (the platform where C language was originally born), the addressing space is 16 bits, so it is reasonable int is also 16 bits. The idea at that time was that the size of int would grow with the development of the processor.

The Mystery of Size

This approach brings some problems. If the size of int varies from platform to platform, the behavior of programs compiled for different processors will vary, which is contrary to the C language "platform-independent" concept.

Unlike int , the size of char is always clearly defined: 8 bits, signed . Despite the name, char is not an abstract type of text characters, but an 8-bit integer. For example, the character "a" will be converted to the number 97 at compile time, which is simple and clear.

What about other types, such as short and long ? Its size is determined by the compiler:

 <code class="c">short // 编译器自行决定大小long // 编译器自行决定大小</code>
Copy after login

The compiler implementer is free to decide its specific size.

Specifications brought by ANSI C (1989)

The ANSI C standard sets some rules:

  • char : at least 8
  • short : at least 16 digits
  • int : at least as big as short (16-bit or 32-bit)
  • long : at least 32

This brings some specifications, but the size of int is still not clear enough. The C99 standard introduces the <stdint.h></stdint.h> header file, and the situation has improved.

Now we have fixed-size integer types:

  • int8_t : 8 bits
  • int16_t : 16 bits
  • int32_t : 32 bits
  • int64_t : 64 bit

From then on, the compiler must implement this header file using a fixed-size type.


The current situation of integers

Today, using modern compilers like GCC and Clang , the size of integers is more predictable:

type size
char 8 bits
Short 16 bits
int 32 bits
long 64 bits (32 bits on 32 bit systems)
long long 64 bits

Although long long is still a bit special, it at least brings consistency (I honestly think long long is cool).


Best Practices

Now we have header files like <stddef.h></stddef.h> and <stdint.h></stdint.h> . Use int only when necessary, such as the return type of main function. For other cases, it is best to use a fixed-size integer type in <stdint.h></stdint.h> ; for array index or loop count, use size_t in <stddef.h></stddef.h> . Hope these suggestions help you avoid some trouble.

Thank you for reading!

The above is the detailed content of Integers in C: a little history. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Rexas Finance (RXS) can surpass Solana (Sol), Cardano (ADA), XRP and Dogecoin (Doge) in 2025 Rexas Finance (RXS) can surpass Solana (Sol), Cardano (ADA), XRP and Dogecoin (Doge) in 2025 Apr 21, 2025 pm 02:30 PM

In the volatile cryptocurrency market, investors are looking for alternatives that go beyond popular currencies. Although well-known cryptocurrencies such as Solana (SOL), Cardano (ADA), XRP and Dogecoin (DOGE) also face challenges such as market sentiment, regulatory uncertainty and scalability. However, a new emerging project, RexasFinance (RXS), is emerging. It does not rely on celebrity effects or hype, but focuses on combining real-world assets (RWA) with blockchain technology to provide investors with an innovative way to invest. This strategy makes it hoped to be one of the most successful projects of 2025. RexasFi

The global unkillable token market has begun the new moon in April 2025 healthy and strong The global unkillable token market has begun the new moon in April 2025 healthy and strong Apr 20, 2025 pm 06:21 PM

DefiDungeons, an NFT series in a fantasy placement RPG game powered by the Solana blockchain, showed strong market performance at the beginning of April 2025. The global NFT market started strongly in April after weeks of growth in trading volume. In the past 24 hours, the total NFT transaction volume reached US$14 million, with trading volume soaring 46% from the previous day. Here are the hottest NFT series in the first week of April: DefiDungeonsNFT series: This fantasy placement RPG game NFT on the Solana blockchain became the best-selling NFT series in the first week of April. In the past 24 hours, the transaction volume reached US$1.5 million, with a total market value of more than US$5 million.

Global Asset launches new AI-driven intelligent trading system to improve global trading efficiency Global Asset launches new AI-driven intelligent trading system to improve global trading efficiency Apr 20, 2025 pm 09:06 PM

Global Assets launches a new AI intelligent trading system to lead the new era of trading efficiency! The well-known comprehensive trading platform Global Assets officially launched its AI intelligent trading system, aiming to use technological innovation to improve global trading efficiency, optimize user experience, and contribute to the construction of a safe and reliable global trading platform. The move marks a key step for global assets in the field of smart finance, further consolidating its global market leadership. Opening a new era of technology-driven and open intelligent trading. Against the backdrop of in-depth development of digitalization and intelligence, the trading market's dependence on technology is increasing. The AI ​​intelligent trading system launched by Global Assets integrates cutting-edge technologies such as big data analysis, machine learning and blockchain, and is committed to providing users with intelligent and automated trading services to effectively reduce human factors.

Why is the rise or fall of virtual currency prices? Why is the rise or fall of virtual currency prices? Why is the rise or fall of virtual currency prices? Why is the rise or fall of virtual currency prices? Apr 21, 2025 am 08:57 AM

Factors of rising virtual currency prices include: 1. Increased market demand, 2. Decreased supply, 3. Stimulated positive news, 4. Optimistic market sentiment, 5. Macroeconomic environment; Decline factors include: 1. Decreased market demand, 2. Increased supply, 3. Strike of negative news, 4. Pessimistic market sentiment, 5. Macroeconomic environment.

The list of compliance licenses for the top ten blockchain exchanges. What are the platforms for strict supervision selection? The list of compliance licenses for the top ten blockchain exchanges. What are the platforms for strict supervision selection? Apr 21, 2025 am 08:12 AM

Binance, OKX, Coinbase, Kraken, Huobi, Gate.io, Gemini, XBIT, Bitget and MEXC are all strictly selected platforms for regulatory selection. 1. Binance adapts to supervision by setting up a compliance sub-platform. 2. OKX strengthens compliance management through KYB verification. 3.Coinbase is known for its compliance and user-friendliness. 4.Kraken provides powerful KYC and anti-money laundering measures. 5. Huobi operates in compliance with the Asian market. 6.Gate.io focuses on transaction security and compliance. 7. Gemini focuses on security and transparency. 8.XBIT is a model of decentralized transaction compliance. 9.Bitget continues to work in compliance operations. 10.MEXC passed

Keep up with the pace of Coinjie.com: What is the investment prospect of crypto finance and AaaS business Keep up with the pace of Coinjie.com: What is the investment prospect of crypto finance and AaaS business Apr 21, 2025 am 10:42 AM

The investment prospects of crypto finance and AaaS businesses are analyzed as follows: 1. Opportunities of crypto finance include market size growth, gradual clear regulation and expansion of application scenarios, but face market volatility and technical security challenges. 2. The opportunities of AaaS business lie in the promotion of technological innovation, data value mining and rich application scenarios, but the challenges include technical complexity and market acceptance.

Web3 trading platform ranking_Web3 global exchanges top ten summary Web3 trading platform ranking_Web3 global exchanges top ten summary Apr 21, 2025 am 10:45 AM

Binance is the overlord of the global digital asset trading ecosystem, and its characteristics include: 1. The average daily trading volume exceeds $150 billion, supports 500 trading pairs, covering 98% of mainstream currencies; 2. The innovation matrix covers the derivatives market, Web3 layout and education system; 3. The technical advantages are millisecond matching engines, with peak processing volumes of 1.4 million transactions per second; 4. Compliance progress holds 15-country licenses and establishes compliant entities in Europe and the United States.

Unlock Binance KERNEL airdrop, new gameplay for BNB holding positions Unlock Binance KERNEL airdrop, new gameplay for BNB holding positions Apr 21, 2025 pm 01:06 PM

In the tide of cryptocurrencies, new opportunities and projects continue to emerge. Recently, the KernelDAO (KERNEL) project launched by Binance has attracted much attention, bringing new gameplay and benefits to BNB holders.

See all articles