完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
问候语!我在PCB上有PIC18F66 J60,我有一个简单的程序。我有一些const字符串:并且我使用缓冲区来操作这些字符串:第一行的行是OK!问题是,当我试图执行这个副本第二次(等等),似乎const字符串名称指向另一个位置…所以我在缓冲器中接收随机数字。我做错了什么?
以上来自于百度翻译 以下为原文 Greetings! I have PIC18F66J60 on a pcb and I have a simple program. I have a few const strings: const unsigned char *Command4Respond="Set date time responce"; And I`m using a buffer to manipulate these strings: volatile unsigned char StringBuffer[50]; unsigned char *buffer=&StringBuffer[0]; strcpy(buffer,Command4Respond); The first execution of this row is OK! The problem is when I tried to execute this copy second time(and so on) it seems the const string name is pointing to another location... So I receive random numbers into the buffer. What am I doing wrong? |
|
相关推荐
19个回答
|
|
奇怪,展示你的完整代码……还有,为什么“无符号字符”?
以上来自于百度翻译 以下为原文 Strange, show your complete code... Also, why "unsigned char" ? |
|
|
|
容易验证-检查是否命令4DRead已经改变了值。
以上来自于百度翻译 以下为原文 Easily verified -- check to see if Command4Respond has changed value or not. |
|
|
|
为了安全起见,如果不是T*const xSO,指针和指针指向的都是const unconch-unchar命令[4]响应[]通知响应拼写;然后使用命令2Rebug(或者如果您不确定数组的名称是指向该数组的指针)n使用and &命令2响应(0)作为字符串的指针。
以上来自于百度翻译 以下为原文 just to be safe, should it not be const T * const x so that both the pointer AND what the pointer points to are const try this const unsigned char Command4Response[] = "notice response spelling"; then use Command2Response (or if you are uncertain that the name of an array is a pointer to that array, then use &Command2Response[0]) as the pointer to the string. |
|
|
|
同意将它声明为数组命令4Real[]是更好的,因为它不能被赋值一个新的值——它是不可变的。在OP代码中必须有一个bug,指针Reavd4Read的值发生了变化。
以上来自于百度翻译 以下为原文 Agree declaring it as an array Command4Respond[] is better, because it cannot be assigned a new value -- it's immutable. There has to be a bug in OP code where the value of the pointer Command4Respond got changed. |
|
|
|
我想你在里面滑了两个“2”,而不是“4”S。前面提到的“无符号”是必要的吗?除非对这些值进行算术运算,否则我看不到签名和无符号之间的区别,对吗?可能不会伤害任何东西,但如果不需要它只是复杂的文字一些…
以上来自于百度翻译 以下为原文 I think you slipped a couple of "2"s in there instead of "4"s. Also as mentioned earlier is the "unsigned" necessary? Unless arithmetic is performed on the values I see no difference between signed and unsigned, correct? Probably will not hurt anything but if not needed it just complicates the text some... |
|
|
|
对于XC8,普通字符的类型是无符号字符。
以上来自于百度翻译 以下为原文 For XC8, the type of a plain char is unsigned char. |
|
|
|
对于XC8,一个普通字符的类型是unChar char。是的,我意识到,我的问题实际上是显式声明,它是一个“无符号char”,它只需要“char”(与默认的“符号char”相同),特别是如果没有算术运算的话。在价值上形成。
以上来自于百度翻译 以下为原文 For XC8, the type of a plain char is unsigned char. Yes I realize that however my question is actually is the explicit declaration as an "unsigned char" needed or of any value over just "char" (which would be the same as "signed char" by default), especially if no arithmetic operations are to be performed on the values. |
|
|
|
直到一个人开始搜索字符串中的一个字符,我的2美分…
以上来自于百度翻译 以下为原文 Hi Until one starts searching a character in a string. Just my 2 cents... Best regards Jorge |
|
|
|
搜索是如何起作用的?我猜如果搜索方法使用算术而不是比较,它可能会陷入麻烦,但为什么要这样做呢?
以上来自于百度翻译 以下为原文 How does searching make a difference? I guess if the search method uses arithmetic instead of comparisons it may get into trouble but why do that? |
|
|
|
字符串文字是“char”,不是无符号字符或符号char。指向字符串文字的指针应该是“char”。
以上来自于百度翻译 以下为原文 A string literal is "char", not unsigned char or signed char. A pointer to a string literal should be "char". |
|
|
|
因此,声明中的差异更多的是确保变量类型与编译器函数所期望的(原型中声明的)匹配,从而避免类型错误匹配错误。我可以接受。在不同的文献/编译器实现中,看起来“char”类型的处理非常不一致。
以上来自于百度翻译 以下为原文 So the differences in the declarations are more to be sure the variable type matches what compiler functions are expecting (declared in the prototypes) and thus avoid type mis-match errors. I can accept that. It does seem the "char" type is handled very inconsistently in different literature/compiler implementations. |
|
|
|
除了与“0”(0)的比较之外,请您解释一下没有算术是如何进行比较的。我不知道怎么办。
以上来自于百度翻译 以下为原文 Hi With the exception of comparision with "0" (zero). Would you mind explaining us how a comparision is made without arithmetics? I don't know how. Best regards Jorge |
|
|
|
为了将一个8位值与另一个8位值进行相等性比较,不需要做加法或减法(算术)。逻辑操作可以使用,逻辑操作一般不关心如果8位值是有符号的或无符号的值。
以上来自于百度翻译 以下为原文 To compare one 8 bit value against another 8 bit value for equality it is not required to do addition or subtraction (arithmetic). Logic operations can be used and logic operation do not generally care if the 8 bit value is a signed or unsigned value. |
|
|
|
我懒惰,所以我会坚持:为字符的ASCII字符,如字面SungSun-Char char的8位无符号整数0到255符号char的8位有符号整数- 128到+127,尽管XC8用户指南推荐什么,
以上来自于百度翻译 以下为原文 I'm lazy so I will stick with:
|
|
|
|
在实践中,我通常同意明确声明所有变量/对象的类型的建议,我认为这是一个很长的方式来记录程序员的意图(也有助于可怕的“便携性”)。在我看来,多年来,字符类型一直比其他类型更难处理。我还没有适应“Untu8”和类似的“标准”声明,太多的旧习惯…
以上来自于百度翻译 以下为原文 In practice I generally agree with the recommendation to explicitly declare the type of all variables/objects, I think it goes a long way to self-document the intent of the programmer (also helps with the dreaded "portability"). It just seems to me that the char type has been more inconsistently dealt with over the years than any other type. And I just haven't become comfortable with the "uint_8" and similar "standard" declarations, too many old habits.... |
|
|
|
你忽视了那个建议是正确的。它应该是合格的,“如果你是使用字符类型作为一个小整数,而不是一个字符。”
以上来自于百度翻译 以下为原文 You are right to ignore that advice. It should be qualified with, "if you are are using a char type as a small integer rather than a character." |
|
|
|
字符是一种特殊情况,所以经常会混淆它。与其他整数类型不同,char、char char和unchar字符是三种不同类型。后两个是小整数,前者是字符。在编写代码时,您不需要知道纯CHAR是签名还是未签名,或者命令行选项是什么,因为代码不应该关心。
以上来自于百度翻译 以下为原文 char is a special case, so there is often confusion surrounding it. Unlike other integer types, char, signed char, and unsigned char are three distinct types. The latter two are for small integers, and the former for characters. There is no circumstance when writing code that you need to know whether plain char is signed or unsigned, or what the command line option is that controls that, because your code should never care. |
|
|
|
我认为C标准允许字符根据实现而被签名或未签名。
以上来自于百度翻译 以下为原文 I think the C standard allows char to be signed or unsigned depending on implementation. |
|
|
|
事实上,我更喜欢使用字符字符,而对于8位整数则使用UIT88T和It8It。
以上来自于百度翻译 以下为原文 Actually I prefer to use char for characters, and uint8_t and int8_t for 8-bit integers. |
|
|
|
只有小组成员才能发言,加入小组>>
5163 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3174 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
732浏览 1评论
615浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
505浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
631浏览 0评论
528浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-23 18:55 , Processed in 1.648289 second(s), Total 115, Slave 98 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号