Fundamentals 9 min read

Master static, volatile, sizeof, and I2C for Embedded C

This guide explains the purposes and effects of the C/C++ static and volatile keywords, compares the sizeof operator with strlen, describes reliable methods for comparing floating‑point numbers, outlines how floating‑point operations affect STM32 interrupt performance, and provides a concise overview of the I²C protocol and address configuration on STM32 devices.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master static, volatile, sizeof, and I2C for Embedded C

static keyword

The static specifier can be applied to local variables, global variables, functions, and class members. When used with a local variable, it makes the variable persist for the lifetime of the program and stores it in the static data area; initialization occurs before main starts and destruction happens when the program exits.

Applied to a global variable, static does not change its storage location (global variables are already in the static area) but limits its linkage to the translation unit, preventing other files from accessing it.

When placed before a function definition, the function gains internal linkage, meaning it can be called only from the file where it is defined.

For class members, static makes the data member shared by all instances of the class (including derived classes). Static data members must be defined outside the class, e.g., int Base::var = 10;. Static member functions do not have a this pointer and can only access other static members.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

volatileC++staticSTM32I2Cfloating-point
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.