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

查看:106
本文介绍了与函数相比,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栈已分配的内存,如果我在的地方放置0开始,这将是一个只是在内存中的reaplacement先前分配.因此,请告诉我在这种情况下它将如何消耗更多的内存.我不确定我的想法是正确的,如果我错了,请纠正我.

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天全站免登陆