Intermediate Variables in Siemens PLC Programming

Intermediate Variables in Siemens PLC Programming

Note that in the programming system of Siemens PLCs (especially TIA Portal), the more professional and accurate terms are Temporary Variables and Static Variables, which typically play the role of “intermediate variables.” The term “intermediate variable” is more of a functional description. Below, I will elaborate on its core concepts. — 1. Principle: The “Draft … Read more

Pitfalls of Static Variables in C: Why the Reset Function Cannot Change Its Value?

Pitfalls of Static Variables in C: Why the Reset Function Cannot Change Its Value?

Hello everyone, I am a programmer who loves to share. I am happy to share my experiences and understanding from my work. -begin- Title: What is the output of the following code? #include <stdio.h> int count() { static int num = 0; num++; return num; } void reset() { int num = 0; printf(“num in … Read more

Interpretation of Google C++ Style Guide Series Part 2 (Scope)

Link to Previous Issue:Interpretation of Google C++ Style Guide Series Part 1 (Header Files) 2.1 Namespaces Except for a few special cases, code should be placed within a namespace, which should have a unique name that includes the project name and may optionally include the file path. The use of <span>using namespace foo</span> is prohibited, … Read more

Understanding the Differences Between Static and Temp Variables in PLCs

Understanding the Differences Between Static and Temp Variables in PLCs

Hello everyone, I received a submission from a fan asking me to explain the differences between Static and Temp variables. Newcomers in the field may find these two concepts a bit difficult to understand. In this article, I will clarify the differences between Static and Temp variables through a few simple examples, along with an … Read more

Exploring Static Variables in C++11 Lazy Singleton Pattern

Exploring Static Variables in C++11 Lazy Singleton Pattern

The singleton pattern in C++11 is one of the best practices we are familiar with. It utilizes the characteristics of static variables to safely implement lazy initialization, thread safety, and automatic memory management with very concise code. The implementation of the lazy singleton pattern in C++11 is roughly as follows: #include <iostream> class Singleton { … Read more

Comprehensive Analysis of Variable Scope in C++: Visibility Rules from Local to Global

Comprehensive Analysis of Variable Scope in C++: Visibility Rules from Local to Global

Variable scope is a very important concept in C++, determining the visibility and lifecycle of variables within a program. Understanding variable scope is crucial for writing correct and efficient C++ programs. 1. Overview of Variable Scope In C++, variable scope refers to the range within which a variable can be accessed in a program. C++ … Read more

C Language – The Lifecycle of Variables: How to Retain the Previous Value?

C Language - The Lifecycle of Variables: How to Retain the Previous Value?

First, please review the previous article that used the counter in 【C Language】 – What is a Function Callback, and How to Implement It? Have you ever thought about: How does the count value retain its previous value in the next cycle? After entering the next cycle, will the variable value still exist before the … Read more

Common Misuses and Knowledge of C Language in Microcontrollers

Common Misuses and Knowledge of C Language in Microcontrollers

When learning about microcontrollers, one truly understands what the C language is and what it is used for. However, the application of C language in embedded systems is just a small part of its overall usage, and there are many other applications as well. We won’t discuss those here. Are we not making many mistakes … Read more

Function Pointers and Pointer Functions in C++

Click the above“Mechanical and Electronic Engineering Technology” to follow us 1. Function Pointers In C++, a function pointer is a pointer that points to a function. They can be used in various scenarios such as callback functions, event handling systems, sorting algorithms, etc. Understanding the type of the function and how to declare and use … Read more