Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use C language functions and macros

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to use C language functions and macros". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought. Let's study and learn how C language functions and macros are used.

Functions and macros

Macros are directly replaced and expanded by preprocessors, and the compiler does not know that macros exist.

A function is an entity compiled directly by the compiler, and the calling behavior is determined by the compiler.

Using macros multiple times will result in an increase in the size of the final executable program

The function is executed by a jump, and only one function body exists in memory.

Macros are more efficient than functions because they are expanded directly and have no calling overhead.

When a function is called, an activity record is created, which is not as efficient as a macro

Let's take a look at an example of functions and macros. Let's look at this program first:

# include # define RESET (p, len)\ while (len > 0)\ ((char*) p) [--len] = 0 void reset (void* p, int len) {while (len > 0) ((char*) p) [--len] = 0;} int main () {int array [] = {1,2,3,4,5}; int len = sizeof (array); int I = 0 RESET (array, len); for (iTuno; I)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report