Singleton Pattern in Embedded C: Writing ‘Globally Unique’ More Stably

In embedded projects, some resources are inherently unique: watchdog timers, RTCs, system clocks, debug serial ports, loggers, system configuration managers, CRC modules… If these modules are carelessly piled up with global variables, issues such as initialization order chaos, difficult-to-trace write access, and ISR/task concurrency collisions will inevitably arise. The goal of the singleton pattern is … Read more

Using Macros in Embedded C Language Effectively

Embedded engineers commonly use macros when coding in C language and debugging. Through continuous engineering experience, I have summarized many useful macros that can be applied to most embedded C language projects, ensuring high portability and readability. Below are some commonly used macros that engineers can save for future use as needed! 1. Preventing a … Read more

Differences Between Embedded C and Standard C Programming

Today, we will once again strengthen our understanding of the characteristics of embedded C programming. Understanding these differences will solidify our cognitive foundation for developing efficient, robust, and portable embedded software! First, it must be clear: from a syntactical perspective, embedded C and standard C are the same language. They share the same syntax, keywords, … Read more

9 Major ‘Black Magic’ Techniques and Optimization Tips for Embedded C Language

“Embedded development is often constrained by resource limitations and hardware interaction requirements, making standard C language difficult to balance efficiency and stability. The ‘black magic’ of embedded C is a precise solution to these pain points. They can constrain the compiler, manipulate hardware, and avoid memory and interrupt issues, serving as a key step from … Read more

Commenting Standards for Embedded C Language Coding

What is important when looking at source code? Besides various coding standards, one significant aspect is comments. Although writing comments can be painful, they are crucial for ensuring code readability. Below, we will discuss how and where to comment. Commenting Style 1. Overview Generally, use // or /* */; just ensure consistency. 2. Explanation Both … Read more

Understanding the Implementation Principle of Zero-Length Arrays in Embedded C

Understanding the Implementation Principle of Zero-Length Arrays in Embedded C

I am Lao Wen, an embedded engineer who loves learning.Follow me to become even better together! Concept of Zero-Length Arrays: As we all know, <span>GNU/GCC</span> has made practical extensions to the standard <span>C/C++</span>, and zero-length arrays (Arrays of Length Zero) are one of the well-known extensions. In most cases, they are used in variable-length arrays, … Read more

Using State Machine Concepts in Embedded C Programming to Handle Complex Logic

Using State Machine Concepts in Embedded C Programming to Handle Complex Logic

The state machine pattern is a behavioral pattern that effectively implements different state transitions through polymorphism. Unfortunately, in embedded environments, one often has to write pure C code while also considering reentrancy and multitasking request transitions, making the implementation quite challenging. Recently, while reviewing an open-source system, I came across an implementation of a state … Read more

Summary of Debugging Techniques and Macro Usage in Embedded C Programming

Summary of Debugging Techniques and Macro Usage in Embedded C Programming

1. Debugging Related Macros When compiling programs with gcc on Linux, there are some special syntax rules for debugging statements. During the gcc compilation process, certain macros are generated that can be used to print information about the current source file, including the current file, the currently running function, and the current line of code. … Read more

Design Patterns: Exploration of Embedded C Language Implementation – Conclusion

Design Patterns: Exploration of Embedded C Language Implementation - Conclusion

Introduction:This article will provide a brief review of the patterns introduced in this series and discuss the benefits and considerations of using patterns in software design. It will also cover how we can apply these patterns in our actual software development.Pattern Summary: Strategy PatternDefines a family of algorithms, encapsulates them, and makes them interchangeable, allowing … Read more

Interesting Facts About Embedded C Language! The Role of the Last ‘end’ in Enumerations

Interesting Facts About Embedded C Language! The Role of the Last 'end' in Enumerations

Click on the “Little Wheat Uncle” above, select “Top/Star Public Account” for benefits and valuable content, delivered to everyone promptly. Hello, I am Little Wheat. I saw this question on Zhihu, and at first, I had some doubts. After researching some materials, I would like to briefly share my views on this issue. How large … Read more