完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我想在我的代码中使用指针来构造,因为我有使用这个表单的库。我遇到的问题是,当我试图访问结构中的一个成员时,就会抛出异常。我用XC32编译器使用PIC32 MM0256GPM028。这里是我的代码(注意,这是生成异常的最简单的代码形式),在这里,当我尝试将Tun1成员设置为0时,出现异常。有趣的是,我尝试了同样的代码在PICT32 MX795F512L中,没有例外发生并且工作良好。有什么评论吗?提前感谢。
以上来自于百度翻译 以下为原文 Hi all, I am trying to use Pointer to Struct in my code since I have library which uses that form. The problem I encounter is when ever I try to access a member in the structure a exception is thrown. I am using PIC32MM0256GPM028 with XC32 compiler. Here is my code (note this is the simplest form of code which generate the exception) #include "mcc_generated_files/mcc.h" #include "common.h" #include "mcc_generated_files/spi2.h" #include unsigned char rx_buffer; typedef struct{ unsigned int temp1; unsigned char temp2; }FIELD_UNIT; FIELD_UNIT *Field_Unit; /* Main application */ int main(void) { // initialize the device SYSTEM_Initialize(); // When using interrupts, you need to set the Global Interrupt Enable bits // Use the following macros to: // Enable the Global Interrupts //INTERRUPT_GlobalEnable(); // Disable the Global Interrupts //INTERRUPT_GlobalDisable(); while(1) { //IO_RB9_Toggle(); Field_Unit->temp1=0; //<---At this point exception occurs. } } /** End of File Here, I when I try to set the temp1 member to zero an exception occur. Interestingly, I tried the same code in PIC32MX795F512L and no exceptions occur and works fine. Any comments? Thanks in advance. |
|
相关推荐
6个回答
|
|
TyEndof实际上不创建变量,它只是生成一个可以用来创建变量的名称。该代码创建了一个指向FieldIyType单元的变量的指针,但是在该代码中的任何地方都没有字段FieldUngy变量的定义,因此指针仍然是空的。
以上来自于百度翻译 以下为原文 A typedef doesn't actually create a variable, it just makes a name you can then use to create variables. That code creates a pointer to a variable of type FIELD_UNIT, but there is no definition of a FIELD_UNIT variable anywhere in that code, so the pointer will still be NULL. |
|
|
|
您的问题与结构无关,错误是声明一个指针,而不是设置指针指向任何东西。你需要一些类似的东西:FieldIn单位S;FieldIn单位=&;
以上来自于百度翻译 以下为原文 Your problem isn't really related to structs; the error is that you're declaring a pointer and you don't set it to point to anything. You need something like: FIELD_UNIT s; Field_Unit = &s; |
|
|
|
谢谢你的回复。然而,我并不清楚。你能用小代码片段给我看看吗?
以上来自于百度翻译 以下为原文 Thanks for the reply. However it is not clear to me. Can you just show it to me in small code snippet.? |
|
|
|
只需添加两行诗句给你,直接在源代码中的这行之后。
以上来自于百度翻译 以下为原文 Just add the two lines jtemples gave you, straight after this line in your source FIELD_UNIT *Field_Unit; |
|
|
|
更正时,不能将可执行行放置在任何函数之外。
以上来自于百度翻译 以下为原文 Correction, you can't put an executable line outside any function. Instead, replace FIELD_UNIT *Field_Unit; with FIELD_UNIT s; FIELD_UNIT *Field_Unit = &s; |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
5159 浏览 9 评论
1998 浏览 8 评论
1927 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3170 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2224 浏览 5 评论
726浏览 1评论
612浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
501浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
625浏览 0评论
524浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-20 20:30 , Processed in 1.271290 second(s), Total 88, Slave 71 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号