完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我只是想找出这两种类型的区别。它们都是全局变量,我可以在源文件[/COND]中的任何源文件中使用它们,因为我可以注意到TyPulfFrand使用的内存比Extn int更多。在其他情况下,我可以理解(如果我错了,请纠正我),在易失性中,您可以在一个变量中添加更多的功能。例如,我的全局计数器可以有价值或状态,或者任何我想要的东西。
以上来自于百度翻译 以下为原文 I'm just trying to find the difference between this two types. Both of them are global variables, and i can use them in any of my source files. Header typedef structIn Source file volatile Fuctions GlobalCounter; //case1 int GlobalCounter2; //case2[/code] As i can notice typedef-volatile uses more ram than extern int. In other case as i can understand (correct me if i am wrong), in volatile you can add more fuctions in one variable. Example maybe my globalcounter can have Value or Status or anything else i want. |
|
相关推荐
3个回答
|
|
我不知道为什么会这样。根据我的理解,只要启用了优化,就不应该使用更多的RAM。它可能会使用更多的ROM(如果你使用变量),因为任何访问必须直接进入RAM(因为易失性),并且不能通过使用寄存器来优化,这可能需要更多的操作。这与波动无关。易挥发的手段,每个访问(读或写)需要应用于变量。理论上,它可以通过其他效果(例如,外部输入,或中断或通过任何方式)随时改变。编译器不允许将变量保存在寄存器中,以优化和重用不同操作的值。Stutt的意思是,你正在创建你想要的任何类型的多个变量的“结构”,甚至可以包括数组、联合或其他结构。
以上来自于百度翻译 以下为原文 I don't know why this is the case. To my understanding it should not use more RAM, as long as you have optimization enabled. It might use more ROM (if you use the variable), because any access must go to RAM directly (because of volatile) and cannot be optimized by using registers, which might require more operations. This has nothing to do with volatile. Volatile means, that every access (read or write) needs to get applied to the variable. In theory it could get changed anytime by other effects (for example by an external input, or by an interrupt or by whatever). The compiler is not allowed to keep the variable in a register for optimization and reuse that value for different operations. What you are describing is only because of the struct. Struct means, you are creating a "structure" of multiple variables of any type you want, which can even include arrays, unions or other structs. |
|
|
|
你把你的限定符混为一谈。它是“结构”,让你将变量组合在一起,而不是“易失性”。它是访问结构的更多工作,你不可能为一个变量使用它。在这里使用Type也没有意义。
以上来自于百度翻译 以下为原文 You're getting your qualifiers all mixed up. It is "struct" that lets you group variables together, not "volatile". It's more work to access a struct, there' no way you'd use it for a single variable. There's no point using a typedef here either. |
|
|
|
TyPulf根本不使用任何内存:TyBuffsStult{StultBigaGyt*Prv;StultBigaLyt*NeXT;未签名的long long DATA(10000);} BigaHyt;//没有内存使用BigaAt*Biga;//不yyf(NUL= =(Biga= MeMyCalLoc(100,SigeOf(BigaYt))){(1);} /现在它不把变量放在头上。ER文件。
以上来自于百度翻译 以下为原文 typedef does not use any memory at all: typedef struct{ struct BigA_t *Prev; struct BigA_t *Next; unsigned long long Data[10000]; }BigA_t; //no memory used BigA_t *bigA; //not yet if(NULL==(bigA=mem_calloc(100, sizeof(BigA_t))) {puts("Alloc failr"); while(1);} //now it does Do not put variables in header files. |
|
|
|
只有小组成员才能发言,加入小组>>
5161 浏览 9 评论
1999 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3171 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
731浏览 1评论
613浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
629浏览 0评论
527浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 20:03 , Processed in 1.355290 second(s), Total 79, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号