stm32 library file_line function

Publisher:温柔的爱情Latest update time:2016-07-27 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
definition  

 Inline functions have the structure of functions from the source code level, but after compilation, they do not have the properties of functions. During compilation, similar to macro replacement, the function body is used to replace the function name at the call site. Generally, the inline modifier is used in the code, but whether an inline function can be formed depends on the specific processing of the compiler on the function definition. 

 

motivation

  Inline expansion is used to eliminate the time overhead of a function call. It is usually used for frequently executed functions. A small memory footprint is a great benefit for functions. Without inlining functions, the compiler can decide which functions to inline. The programmer has little or no control over which functions are inlined and which are not. Given this degree of control, the programmer can choose to inline for a specific application. 

 

Function inlining problem

  Apart from the related issue of inline expansion in general, language features as an inline function may not be considered valuable for the reasons they appear, for a number of reasons: 

    Often, a compiler is in a better position than a human to decide whether a particular function should be inlined. Sometimes, the compiler may not be able to inline as many functions as the programmer indicates. 

 

  An important point to note is that the code (inline function) gets exposed to its clients (calling functions). 

 

  As functions evolve, they may become suitable for inlining where they were not before, or no longer suitable for inlining where they were before. While inlining or de-inlining a function is easier than converting from macros, it still requires additional maintenance and generally yields relatively little benefit. 

 

  The proliferation of native C-style compilation systems can increase compilation time for inline functions, because an intermediate representation of their bodies is copied to each call site where they are inlined. The possible increase in code size is mirrored by the possible increase in compilation time. 

 

  The C99 inline specification requires only one additional external definition of a function in another compilation unit, and the corresponding inline definition can occur multiple times in different compilation units if the function is used in place. This can easily lead to errors in the linker because such definitions are not provided by the programmer. For this reason, inline is often used together with static in C99 to also give the function internal linkage. 

 

  In C++, it is necessary to define an inline function in every module (compilation unit) to use a normal function, and it must be defined in only one module. Otherwise, it would be impossible to compile one module independently of all other modules. 

 

  For issues with functionality per se, rather than the language, see Problems with expanding with inline. 

 

Macro comparison

  The function of inline function is similar to that of preprocessor macro. I believe everyone has used preprocessor macro. We often define some macros, such as 

 

  #define TABLE_COMP(x) ((x)>0?(x):0) 

 

  A macro is defined. 

 

  Why use macros? Because the function call must transfer the program execution order to the function 

 

  The address stored in the memory will return to the execution after the program content of the function is executed. 

 

  This transfer operation requires saving the scene and memorizing the execution location before transferring execution. 

 

  After the function is called, it needs to restore the original address and continue to execute according to the original saved address. 

 

  The macro only takes a certain amount of time and space to process. 

 

  Code expansion does not require additional space and time overhead, so calling a macro is faster than calling a 

 

  Functions are more efficient. 

 

  But macros also have many unsatisfactory aspects. 

 

  1. Macros cannot access private members of objects. 

 

  2. The definition of macros can easily be ambiguous. 

 

  Let’s take an example: 

 

  #define TABLE_MULTI(x) (x*x) 

 

  We call it with a number, TABLE_MULTI(10), which seems to be correct. 

 

  The result returns 100, which is correct. However, if we call it with TABLE_MULTI(10+10), 

 

  The expected result is 400, but the result of the macro call is (10+10*10+10), which is 120. 

 

  This is obviously not the result we want. One way to avoid these errors is to put parentheses around the macro parameters. 

 

  #define TABLE_MULTI(x) ((x)*(x)) 

 

  This ensures that there will be no errors, but even with this definition, the macro may still 

 

  Errors occur when, for example, they call it with TABLE_MULTI(a++) when they expect to get (a+1)*(a+1). 

 

  The result is, but what is the actual result? We can look at the macro expansion result: (a++)*(a++), if the value of a is 

 

  4, the result we get is 4*4 = 16, a = 6. And the result we expect is 5*5=25, which is a problem again. 

 

  In fact, there are also these problems in some C library functions. For example: Toupper (* pChar ++) will 

 

  pChar performs two ++ operations because Toupper is actually a macro as well. 

 

  We can see that macros have some unavoidable problems. How can we solve them? 

 

  The following is to use the inline function I will introduce to solve these problems. We can use the inline function 

 

  To replace the macro definition. And in fact we can completely replace the preprocessor macro with an inline function. 

 

  The difference between inline functions and macros is that macros are replaced by the preprocessor, while inline functions are replaced by 

 

  This is achieved through compiler control. Inline functions are real functions that are only used when needed. 

 

  When inline functions are expanded like macros, the stack push of function parameters is cancelled, reducing the number of call openings. 

 

  You can call an inline function just like a function without having to worry about the overhead of processing macros. 

 

  some problems. 

 

  We can use Inline to define inline functions, however, any function defined in the class declaration part 

 

  All functions are automatically considered inline functions. 

 

  Next we introduce the usage of inline functions. 

 

  Inline functions must be declared together with the function body to be effective. 

 

  Inline Tablefunction(int I) has no effect. The compiler just treats the function as a normal function. 

 

  To declare a function, we must define the function body. 

 

  Inline tablefunction(int I) {return I*I}; 

 

  This is how we define an inline function. We can call it like a normal function. 

 

  However, the execution speed is faster than that of general functions. 

 

  We can also define functions defined outside a class as inline functions, for example: 

 

  Class TableClass{ 

 

  Private: 

 

  Int I,j; 

 

  Public: 

 

  Int add() { return I+j;}; 

 

  Inline int dec() { return Ij;} 

 

  Int GetNum(); 

 

  } 

 

  inline int tableclass::GetNum(){ 

 

  return I; 

 

  } 

 

  The three functions declared above are all inline functions. In C++, the function body is defined inside the class. 

 

  Functions are considered inline functions by default, regardless of whether you have the inline keyword.

 

  Inline functions are most widely used in C++ classes to define access functions.

 

  In a class, data members are usually defined as private or protected, so that the outside world cannot directly read and write them.

 

  The data of our class members.

 

  The reading and writing of private or protected members must be done using member interface functions. 

    If these read and write member functions are defined as inline functions, better efficiency will be achieved. 

 

  Class sample{ 

 

  Private: 

 

  Int nTest; 

 

  Public: 

 

  Int readtest(){ return nTest;} 

 

  Void settest(int I) {nTest=I;} 

 

  } 

 

  Of course, inline functions also have certain limitations. That is, the execution code in the function cannot be too much, such as 

 

  If the body of the inline function is too large, the general compiler will abandon the inline method and use the normal method. 

 

  Call the function. In this way, the execution efficiency of the inline function is the same as that of the ordinary function. 

 

Precautions

  Things to note when using inline functions 

 

  Inline functions have the characteristics of general functions. The only difference between them and general functions is the processing of function calls. When a general function is called, the program execution right is transferred to the called function and then returned to the calling function; when an inline function is called, the calling expression is replaced by the inline function body. When using inline functions, the following points should be noted: 1. Loop statements and switch statements are not allowed in inline functions. If an inline function has these statements, the compiler will treat the function as a normal function and generate function call code. Recursive functions (functions that call themselves) cannot be used as inline functions. Inline functions are only suitable for small functions with only 1 to 5 lines. For a large function with many statements, the overhead of function calls and returns is relatively insignificant, so there is no need to implement it with inline functions. 2. The definition of an inline function must appear before the inline function is called for the first time. 3. In the class structure mentioned in this column, all functions defined inside the class description are inline functions.

Keywords:stm32 Reference address:stm32 library file_line function

Previous article:IAR STM32 absolute address positioning of functions and variables
Next article:STM32 keil mdk startup code analysis

Recommended ReadingLatest update time:2024-11-16 19:56

STM32 RTC and standby mode
1. Background Recently I have used low power mode - standby mode and RTC wake-up, so I reorganized RTC and sleep mode - standby mode. 1.1 What is standby mode? Standby mode: Based on the CortexTM-M4F deep sleep mode, where the voltage regulator is disabled, so the 1.2V domain is powered down - the PLL, HSI oscilla
[Microcontroller]
STM32 RTC and standby mode
STM32 Learning 011_Product Development Process (I)
Regarding a product, the process from market research to concept formation, and then to product project establishment and product development requires a long period of work. I read a book called "Hardware System Engineer's Handbook" and felt it necessary to compile it for everyone's reference. When designing a hardwar
[Microcontroller]
stm32 driving LCD
(1) How to write a header file   Example: //  header file file.h                 #ifndef  FILE_H                            //FILE_H  can be written arbitrarily, it is just a label to prevent the header file from being repeatedly defined                 #define  FILE_H                            //It should be the
[Microcontroller]
STM32 serial port configuration (interrupt mode)
The serial port interrupt configuration of STM32 is also very simple. The first step is to configure the UART GPIO port The first step is to configure the UART GPIO port /************************************************ * Name: UART1_GPIO_Configuration * Deion: Configures the uart1 GPIO ports. * Input : No
[Microcontroller]
stm32 initializes three serial ports
serial.c  #include "serial.h"          int fputc(int ch,FILE *p) //The system automatically uses this function when using printf     {         USART_SendData(USART2,(u8)ch);           while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET);         return ch;              }     /*************************************
[Microcontroller]
Storing constants in FLASH in STM32 (CONST keyword)
Today, when I was writing a program, I wanted to store a string constant in the FLASH of STM32. After looking at other people's example programs for a while, I knew that the keyword const was used, but I didn't succeed the first time. Premise: I am using STM32F103ZE microcontroller, The storage range of FLASH is
[Microcontroller]
Use of STM32 ST-LINK Utility
The main function of the STM32 ST-LINK Utility software is mass production (a tool for batch downloading of codes). It is also a practical tool. When we need to view the chip FLASH data, we can quickly locate and find the desired data (provided that no protection is added). Need to be used with STLink. Wir
[Microcontroller]
Use of STM32 ST-LINK Utility
The data before stm32 power off is stored in flash
FLASh must be erased before writing. The following function is an analysis case. void FLASH_WriteByte(u32 addr ,u16 flashdata1) { FLASH_Status FLASHstatus = FLASH_COMPLETE; FLASH_Unlock();//Unlock FLASH programming and erasing controller // FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);//Cl
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号