Understanding Byte Alignment in C and C++

Understanding Byte Alignment in C and C++

Byte Alignment Definition Byte alignment is a memory layout rule in computer programming where the starting address of data in memory must be a multiple of its own size. One can imagine memory as a series of contiguous small boxes, each of size 1 byte, with each box having a unique address starting from 0: … Read more

Understanding Number Systems in C Language

Before learning about data types, let’s first understand the number systems. 1. Decimal (十进制) The number system we use daily, with a base of 10, using digits 0-9. 123 = 1×10² + 2×10¹ + 3×10⁰ 2. Binary (二进制) With a base of 2, using digits 0 and 1. 1101₂ = 1×2³ + 1×2² + 0×2¹ … Read more

Understanding Byte Alignment in Embedded C Language

Understanding Byte Alignment in Embedded C Language

Recently, a fan asked me: “Why is the size of the structure I defined always larger than the sum of the sizes of its member variables?” Don’t worry, this isn’t the compiler “stealing memory”; it hides an important concept—byte alignment. Today, we will explain this using the logic of “arranging books on a shelf” so … Read more

Summary of Microcontroller Basic Concepts

Summary of Microcontroller Basic Concepts

Microcontroller Instruction Execution Let’s consider a question: when we write an instruction into the microcontroller using a programmer, and then take the microcontroller out, it can execute that instruction. So this instruction must be stored somewhere in the microcontroller, and this place can retain the instruction even after the microcontroller loses power. What is this … Read more

Understanding Byte Alignment in Linux

Understanding Byte Alignment in Linux

Recently encountered a problem where ThreadX running on ARM crashed while communicating with DSP using message queues (the final implementation principle is interrupt + shared memory). After investigation, it was found that the structure used for message passing did not consider the issue of byte alignment. Here’s a brief overview of byte alignment issues in … Read more