C 宏存储在内存中的位置以及与函数相比它如何消耗更多内存? [英] Where the C macros stored in memory and how does it consumes more memory compared to functions?

查看:10
本文介绍了C 宏存储在内存中的位置以及与函数相比它如何消耗更多内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索了 C 宏将在哪里存储在内存中,与函数相比,它如何消耗更多内存?无法得到任何令人满意的答案.谁能告诉我确切的答案?

I searched in web where will be the C macros stored in memory and how does it consumes more memory compared to functions? Could not get any satisfying answer .Can anyone please let me know the asnwer exactly ?

有什么方法可以找出c中的宏消耗的内存吗?

is there any way to find out the memory consumed by a macro in c?

我想到的另一个问题是,假设我定义了一个宏#define START 10.并且我有变量 int i = 0,我将用这样的宏替换它 i = START.现在 int i =0 已经在堆栈中分配了内存,如果我将 START 放在 0 的位置,这将只是对先前分配的内存的重新放置.所以请告诉我在这种情况下它将如何消耗更多的内存.我不确定我的想法是否正确,如果我错了,请纠正我.

And one more question comes up in my mind is , Suppose i decalre a macro #define START 10. and i have variable int i = 0, which i would be replacing with macro like this i = START. Now int i =0 has already allocated memory in stack and if i place START in place of 0 , it would be a just a reaplacement in the memory previously allocated. So pls tell me how will it consume more memory in this context. I am not sure what i am thinking is correct , if i am wrong , pls correct me .

以前在本网站上提出的问题没有回答这些情况..

Previous question asked on this site does not answer to these contexts..

谢谢

推荐答案

宏是一个预处理器结构.在编译器甚至看到代码之前,所有宏都被它们的定义替换.

Macros are a preprocessor construct. All macros are replaced by their definitions before the compiler even sees the code.

这意味着如果您使用大量带有大替换的宏,它们将生成大量代码.函数调用不是这样工作的,因为它们调用的单个函数只有代码一次.

This means that if you use a lot of macros with large replacements, they will generate a lot code. Function calls don't work that way, since they call a single function that only has the code once.

没有标准的方法来计算有多少代码是由宏引起的,不.

There is no standard way of figuring out how much code is due to macros, no.

这篇关于C 宏存储在内存中的位置以及与函数相比它如何消耗更多内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆