完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我需要使用‘const int’和‘char const *const’来通知编译器,我的值永远不会改变。我需要成功地完成最小程序和数据存储器。我得到错误:错误在我的源文件中显示。
以上来自于百度翻译 以下为原文 I need to use 'const int' and 'char const * const', to inform compiler that my value will never change. I need to succeed minimum program and data memory. typedef struct{ char const * const Name[2]; const int MaxValue; const int Type; const int EppromLocation; const int NextID; const int PreviousID; } Parameters; extern Parameters MenuRegister[50]; I'm getting errors: a.c:119: error: (364) attempt to modify object qualified const a.c:123: warning: (358) illegal conversion of pointer to integer the error is showing in my source file Parameters MenuRegister[50]; MenuRegister[0].Name[0]="MyName"; MenuRegister[0].MaxValue=1; MenuRegister[0].Type=1; MenuRegister[0].EppromLocation=1; MenuRegister[0].NextID=2; MenuRegister[0].PreviousID=0; |
|
相关推荐
16个回答
|
|
类似的东西:当你第一次创建它时,你可以设置它的常量值,而不是之后,因为它将在程序内存中。程序内存不能以这种方式改变。
以上来自于百度翻译 以下为原文 Something like this: typedef struct{ char const * const Name[2]; const int MaxValue; const int Type; const int EppromLocation; const int NextID; const int PreviousID; } Parameters_t; Parameters_t Parameter={ {{"abc"},{"def"}},1,2,3,4,5}; You can set the constant value when you first create it but not after since it will be in program memory. Program memory cannot be changed in that way. |
|
|
|
搜索:编译时间vs运行时。要添加:如果你正在修改它,那么它不能是常数。你可以指向一个常量内存,比如一个字符串。现在删除const直到它工作。如果它是一个数组,那么你仍然可以把它全部设置成一个,就像我之前的几篇文章。
以上来自于百度翻译 以下为原文 Search: compile time vs runtime. To add: If you are modifying it then it can not be constant. You can point to constant memory such as a string. Remove the const for now until it is working. If it is an array then you still can set it all up in one like I did a few posts ago. |
|
|
|
谢谢你的快速回复。如果我想在源文件中使用多个寄存器呢?源文件出错
以上来自于百度翻译 以下为原文 Thank you for quick reply. What if i want to use multiple registers in source file? Header typedef struct{ char const * const Name[2]; const int MaxValue; const int Type; const int EppromLocation; const int NextID; const int PreviousID; } Parameters_t; Parameters_t Parameter[5]; In source file Parameters_t MenuRegister[5]; void RegisterInit() { MenuRegister[0]={{{"abc"},{"def"}},1,2,3,4,5}; } I'm getting error a.c:17: error: (195) expression syntax a.c:17: error: (312) ";" expected a.c:17: error: (285) no identifier in declaration a.c:17: warning: (374) missing basic type; int assumed |
|
|
|
此语法只能用于初始化,而不应用于赋值。它需要成为宣言的一部分。
以上来自于百度翻译 以下为原文 This syntax can only be used in initialization, not in an assignment. It needs to be part of the declaration. |
|
|
|
该结构将不会放置在程序内存中。这不是永久的。
以上来自于百度翻译 以下为原文 That structure will not be placed in program memory. It is not const. |
|
|
|
你必须在编译时设置数组/Stutt。你仍然在使用常量运行时。你可以这样做一个数组:PosialPyt p [3 ]={{“abc”,“DEF”},1,2,3,4,5 },{“GHI”,“JKL”},6,7,8,9,10 },{{“MNO”,“PQR”},11,12,13,14,15};
以上来自于百度翻译 以下为原文 You have to set the array/struct at compile time. You are still using runtime on constants. You can do an array like this: Parameter_t p[3]= { {{"abc","def"},1,2,3,4,5}, {{"ghi","jkl"},6,7,8,9,10}, {{"mno","pqr"},11,12,13,14,15} }; |
|
|
|
|
|
|
|
如果你这样改变你的结构,它们都是conist.Type,const结构{{};在常量内存中:
以上来自于百度翻译 以下为原文 If you change your structure heading like this, they are all then constants. typedef const struct{}; In constant memory: const Parameter_t p[3]= { {{"abc","def"},1,2,3,4,5}, {{"ghi","jkl"},6,7,8,9,10}, {{"mno","pqr"},11,12,13,14,15} }; |
|
|
|
|
|
|
|
放入程序存储器:
以上来自于百度翻译 以下为原文 To place into program memory: typedef const struct { const char *Name[2]; int MaxValue; int Type; int EppromLocation; int NextID; int PreviousID; } Parameters_t; Parameters_t Parameter[5] = { {{"abc","def"},1,2,3,4,5}, {{"ghi","jkl"},6,7,8,9,0}, {{"mno","pqr"},1,2,3,4,5}, {{"stu","vwx"},6,7,8,9,0}, {{"foo","bar"},1,2,3,4,5} }; |
|
|
|
很好的回答谢谢!第一个问题我可以宣布它们是秘密的。原因是我想读取每个变量名来理解它所做的每件事。例如:等等。它帮助我读取变量名。第二个问题,我可以用不同的寄存器吗?最后一个问题,如果我将包含在一个非静态的值示例中,我会在初始化中一起声明它们吗?
以上来自于百度翻译 以下为原文 Nice answer thanks! First question can i declare them separetaly. The reason is that i want to read each variable name for understanding what everything its doing. Example: Parameters_t Parameter[1].Name = {"abc","def"}; and so on.It Helps me to read variable name. Second question can i use different registers for each one? Parameters_t Parameter[1] = { {{"abc","def"},1,2,3,4,5}; Parameters_t Parameter[2] = { {{"abc","def"},1,2,3,4,5}; Parameters_t Parameter[3] = { {{"abc","def"},1,2,3,4,5}; And last qustion, what if i i will include inside a non static value example typedef const struct { const char *Name[2]; int MaxValue; int Type; int EppromLocation; int NextID; int PreviousID; union { unsigned int Value; unsigned char bytes[2]; }SetValues; } Parameters_t; Can i declare them together in initialize? |
|
|
|
作为声明的一部分,您只能将整个结构初始化一次。你不能把它拆开。我不知道你的意思是“把它们一起声明为初始化”。
以上来自于百度翻译 以下为原文 You can only initialize the entire structure one time as part of the declaration. You can't split it up. I don't know what you mean by "declare them together in initialize". |
|
|
|
它可以帮助我一起读取变量,以便于如果需要更改,示例:所以我需要并列放置const和unconst变量。
以上来自于百度翻译 以下为原文 It helps me to read variables all together, for make it easy if i need to make a change; Example: Register[0].PreviousID=2; Register[0].Name[0]="AAAAA"; Register[0].Name[1]="asdwwew"; Register[0].MaxValue=100; Register[0].MinValue=0; Register[0].SetValues.Value=10; Register[0].NextID=1; So i need to place const and non const variables side by side. |
|
|
|
如果需要,可以在结构中混合const和unconst成员。但是在const成员中设置一个值的唯一方法是声明它。
以上来自于百度翻译 以下为原文 You can mix const and non-const members in a struct if you want. But the only way to set a value in a const member is when it's declared. |
|
|
|
我认为这里有一个失败来掌握初始化代码和可执行代码之间的区别。
以上来自于百度翻译 以下为原文 I think there is a failure here to grasp the difference between initialisation code and executable code. |
|
|
|
那么,QusiTo是,当它们被声明时,我可以设置它们两者的值(const和const)吗?const值也应该在数组内吗?我可以用变量的名字来区分它们吗?就像我的例子一样,我如何在相同的Type结构中使用const和unconst?
以上来自于百度翻译 以下为原文 Ok then the qustion is can i set values both of them (const and non const)when they are declared? Also const values should be inside an array? Can i separate them with the name of its variable? like my example. Also how i will use const and non const inside same typedef struct? |
|
|
|
只有小组成员才能发言,加入小组>>
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:01 , Processed in 1.681807 second(s), Total 107, Slave 90 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号