完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
MPLAB-X与XC-32和和声产生了这个代码,将IP地址存储到程序Flash中:*定义TCPIPPNETWorksDeFultTypIdAddiSsIdx0“192.1680.10”,我试图获得地址(0x1D00×XXXX),其中常量存储在FLASH中:长*AA;AA=和;TCPIPPNETWorksDeFultTypIpAddiSrs]IDX0;编译器说:“警告:从不兼容的指针类型赋值[默认启用]”我认为这是基本C语言的东西,但它不像我预期的那样工作。我尝试了Type:int和Type:长但没有一个工作。
以上来自于百度翻译 以下为原文 -MPLAB-X with XC-32 and HARMony- Harmony generated this code to store an IP address into program flash: #define TCPIP_NETWORK_DEFAULT_IP_ADDRESS_IDX0 "192.168.0.10" I'm trying to get the address (0x1D00_xxxx) of where that constant is stored in flash: long *aa; aa = &TCPIP_NETWORK_DEFAULT_IP_ADDRESS_IDX0; The compiler says: "warning: assignment from incompatible pointer type [enabled by default]" I thought this was basic C language stuff but it doesn't work like I expected it to. I tried type:int and type:long but neither one works. |
|
相关推荐
6个回答
|
|
该字符串的地址是“char *”,而不是“长*”。你不能接受宏的地址。您需要引用任何包含该字符串的对象。
以上来自于百度翻译 以下为原文 The address of that string is a "char *", not a "long *". And you can't take an address of a macro. You need to refer to whatever object contains that string. |
|
|
|
来自http://www. McCys.com /论坛/ M103638.ASPXE确实不需要启动一个新的主题来继续一个现存的问题,它失去了所有已建立的上下文。你似乎不想接受你在以前的主题中收到的建议。SS定义为编译器的文本替换请求,它在程序中不存在,直到它被用于指令中。
以上来自于百度翻译 以下为原文 Comes from http://www.microchip.com/forums/m1036378.aspx There's really no need to start a new topic to continue an existing question, and it loses all the established context. You don't seem to want to beleive the advice you received in your previous topic. A "defined constant" does not have an address. "#define" is simply a text substitution request to the compiler. It does not exist in your program at all until it is used in an instruction. This is "basic C stuff" that you are trying to misuse. |
|
|
|
好的一点。编程C不是MyJooWork,所以需要反复使用一些迭代来找出它的大部分时间。我这样做是因为这里没有人知道如何编码。请澄清一下。我的理解是,当你在C中声明一个常量,编译器会在程序内存中选择一个地址并把它推到那里?在StaskIn.c文件中,我找到了这个常数声明:const TcPIP.NETWorksconfig.AtAtditTyx((未使用))TCPIpIHOSTSO配置[]={/***网络配置索引0 ***/{TCPIPPNETWorksDeFultJIPIADESRSSIDIX0,//IADDR}},这个常数是“文本替换”等于“192.1”吗?68、X存在于程序存储器中吗?
以上来自于百度翻译 以下为原文 Good point. Programming C is not my job so it takes a few iterations of mis-use to figure it out most of the time. I only do this because nobody around here knows how to code. Please clarify something. It was my understanding that when you declare a constant in C that the compiler would choose an address in program memory and shove it in there?? In the system_init.c file I found this constant declaration: const TCPIP_NETWORK_CONFIG __attribute__((unused)) TCPIP_HOSTS_CONFIGURATION[] = { /*** Network Configuration Index 0 ***/ { TCPIP_NETWORK_DEFAULT_IP_ADDRESS_IDX0, // ipAddr }, }; Does this constant which was "text substituted" to equal "192.168.0.x" exist in program memory? |
|
|
|
可能,但是我们需要看看TCPIPPNETWORKY CONFIG是什么。
以上来自于百度翻译 以下为原文 Probably, but we'd need to see what TCPIP_NETWORK_CONFIG is to be sure. |
|
|
|
我想补充一下,在语句中使用的字符串文字已经作为对象存在。只需使用字符串的指针就可以使用字符串。字符串常量是数组,这些数组自动表示为指针(到第一个元素),因此不需要使用ANP;因此,你可以直接把它们分配给一个指针,而不需要任何数组变量来保存字符串本身。因此,上面的字符串是在最后一行中使用的,它是存在的,并且可以使用它作为指针。您不需要额外的数组变量来保存字符串本身,字符串将存在于程序内存中的某个地方。但是,请注意,字符串可能单独存在于每个编译单元(.c文件)中。例如,如果你有以下的:StrysCyFig .H:TestAu.c:TestBB.C:你的二进制文件可能包含两次字符串,AA和BB指向不同的位置。所以不要尝试比较这样的指针。PS:我修改了示例并添加了一些“const”给char指针。我还建议阅读MPLAB®XC32 C/C++编译器用户指南,第8.9节常量类型和格式。请看这两个例子,其中使用的是“两个”字符串,还有“Hello World”示例。
以上来自于百度翻译 以下为原文 I'd like to add to this, that string literal which is used in a statement is already existing as an object. Just taking the pointer of the string is enough to make the string used. String constants are arrays which automatically are represented as pointer (to the first element) so there is no need to use the &. Therefore, you can assign them directly to a pointer, without any array variable holding the string itself. #define TCPIP_NETWORK_DEFAULT_IP_ADDRESS_IDX0 "192.168.0.10" const char * aa; aa = TCPIP_NETWORK_DEFAULT_IP_ADDRESS_IDX0; Then, please think of an #define always as text replacement. So the above is the same as const char * aa; aa = "192.168.0.10"; Since the string is used in the last line, it is existing, and you can use it as a pointer. You don't need an additional array variable to hold the string itself, and the string will exist somewhere in program memory. However, be aware, that the string might exist in each compile unit (.c file) separately. For example if you have the following: system_config.h: #define TCPIP_NETWORK_DEFAULT_IP_ADDRESS_IDX0 "192.168.0.10" test_aa.c: #include "system_config.h" char const * aa; aa = TCPIP_NETWORK_DEFAULT_IP_ADDRESS_IDX0; test_bb.c: #include "system_config.h" char const * bb; bb = TCPIP_NETWORK_DEFAULT_IP_ADDRESS_IDX0; It is possible that your binary contains the string two times, and aa and bb are pointing to different locations. So don't try to compare such pointers. PS: I modified the examples and added some "const" to the char pointers. I recommend also reading the MPLAB® XC32 C/C++ Compiler User’s Guide, section 8.9 CONSTANT TYPES AND FORMATS. Have a look at the two examples which are using the "two" string, and also the "hello world" examples. |
|
|
|
莫泽,谢谢你对指针的极好解释。在C看来,总是有一种更简单的方法来做事情!我将您的示例插入到代码中,并将其运行到断点。监视窗口给了我插入执行内存的地址,GTO窗口和VoILA!有我的IP地址在Flash。认真…我需要停止写代码深夜。;-)
以上来自于百度翻译 以下为原文 Moser, Thank you for that excellent explanation of the pointer. It seems in 'C' that there's always a simpler way to do things! I plugged your example into my code and ran it to the breakpoint. The watch window gave me the address which I plugged into the execution memory>goto window and voila! there was my IP address in Flash. Seriously....I need to stop writing code late at night. ;-) |
|
|
|
只有小组成员才能发言,加入小组>>
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 19:00 , Processed in 1.218123 second(s), Total 87, Slave 70 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号