Understanding Pointers in C Language (Pointers – Part 1)

Welcome everyone to help me correct my mistakesIn a function like this, we can introduce external variables for use within the function #include<stdio.h>void function(int n){ int m = n*n; printf("%d",m);}int main(){ int n = 2; function(n); return 0;}// Code 1 Output: 4 However, what if we try to modify the value of n directly within … Read more

Usage of extern in C/C++ Language

Declaration of External Variables Modern compilers generally adopt a file-based compilation method, which means that global variables defined in different files are mutually transparent during compilation. In other words, the visibility of global variables is limited to the internal scope of the file during compilation. Here is a simple example. Create a project containing two … Read more

Comparison of Communication Methods Between Embedded System Modules

Comparison of Communication Methods Between Embedded System Modules

Follow our official account to keep the embedded knowledge flowing! 1. Global Variables Global variables are often regarded as “bad design,” but in embedded systems, they are the most performant communication method. The key is not to avoid their use, but rather to design them correctly. The issue with global variables is not performance, but … Read more

Categorizing Functions in Embedded C Code

Categorizing Functions in Embedded C Code

Content Hello everyone, I am Bug Jun~For C developers, functions are definitely not unfamiliar, and you could even type them out with your eyes closed. But have you categorized the functions in C language? When you write a function, do you first think about its functionality or its parameters?Today, I suggest categorizing the functions you … Read more

Python Learning – Variable Scope (Global and Local Variables)

Python Learning - Variable Scope (Global and Local Variables)

The variable scope determines where a variable can be accessed within a program. Python has four main scopes, arranged in the order of lookup: 1. Four Levels of Scope (LEGB Rule) Local – Local Scope Enclosing – Enclosing Scope Global – Global Scope Built-in – Built-in Scope 2. Local Variables vs Global Variables 1. Local … Read more

Core of PLC Programming Standardization

Core of PLC Programming Standardization

Why should M and T be avoided in PLC programs? The core logic of programming standardization. 1. Fundamental Flaws of Global Variables In PLC programming, global variables such as M (memory relay) and T (timer) are widely used but have inherent weaknesses: unclear ownership and a scope that covers the entire program. The M and … Read more

Embedded C Language: Misconceptions and Solutions for Global Variable Usage

Embedded C Language: Misconceptions and Solutions for Global Variable Usage

Click the above to select“Pin/Star Public Account” Welfare and valuable content delivered first-handHello everyone, I am Mai Ge.In embedded development, especially in os-less microcontroller programs, the most common mistake is the rampant use of global variables.This phenomenon is often seen among programmers transitioning from early assembly language and beginners, who tend to treat global variables … Read more

Understanding the Stack in Embedded Programming

Understanding the Stack in Embedded Programming

What is a Variable? A variable can generally be classified as shown in the figure below: The focus of this section is to help everyone understand the memory model of the stack, temporarily ignoring the case of static variables, and we agree on the following: “Global variables” are simply assumed to be “ordinary global variables”; … Read more

Understanding C++ Scope and Namespace

Understanding C++ Scope and Namespace

Preface Every variable, function, array, structure, class, and other entities have their own valid scope, which is the scope of the variable. The namespace is a user-defined scope introduced in ANSI C++ to handle common naming conflicts in programs. Meet/Yourself ➤C++ Scope Every variable, function, array, structure, class, and other entities have their own valid … Read more

Why Fewer Global Variables are Better in Embedded C Programming

Why Fewer Global Variables are Better in Embedded C Programming

Embedded development, especially in os-less microcontroller programs, often suffers from the rampant use of global variables.This phenomenon is common among programmers transitioning from early assembly language and beginners, who tend to treat global variables almost like function parameters.They define numerous chaotic structures in .h files, declare a bunch of externally visible global variables that are … Read more