首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AVR模拟器中的意外指针重新分配

AVR模拟器中的意外指针重新分配
EN

Stack Overflow用户
提问于 2013-08-05 03:17:26
回答 1查看 120关注 0票数 0

下面的函数populateArpeggioArray接受一个指向包含几个成员的类型定义结构的指针,这些成员的身份不一定与我遇到的问题相关。在将指向结构的指针传递给函数sortNoteStack之前,populateArpeggioArray应该对结构的内部元素执行一些操作。

我发现sortNoteStack从不对该结构进行操作,因为在将更改后的值传递给sortNoteStack之前,populateArpeggioArray会在某个时刻更改指向该结构的指针的值。

据我所知,代码的格式似乎是正确的,在结构元素上执行的所有操作都有正确的指针取消引用。据我所见,没有一行代码能够修改指向结构的指针的值。使用const前缀声明结构没有任何帮助,因为它的成员也因此锁定为固定值。

我对这可能是模拟器的问题,而不是代码的问题持开放态度,但如果我写的代码有一些潜在的问题,我当然想知道我做错了什么。

谢谢你的帮助。

-Nick

代码语言:javascript
复制
void populateArpeggioArray(arpeggio* arp) {
        uint8_t i = 0,j=0, newNoteFlag=0;

        for(i=0; i<12; i++) {
            newNoteFlag = 0;
            if(globals.keyboardCurrentState[i]) {                                   /* Check to see if the current state shows that a keyboard button is pressed. */
                arp->sequenceLength++;                                              /* Temporarily increase the sequence length */
                for(j=0;j < arp->sequenceLength;j++) {                              /* Check the pitch of each note currently in the note stack */
                    if(globals.keyboardNotes[i] == arp->notesUnordered[j].pitch) {  /* If the currently selected note is already present in the note stack, */
                        arp->sequenceLength--;  
                        newNoteFlag = 1;                                            /* undo the temporary sequence length increase */
                    }           
                }   
                if(!newNoteFlag) {
                    arp->notesOrdered[arp->sequenceLength].pitch = globals.keyboardNotes[i]+liveArpeggio.transposeShift;
                    arp->notesUnordered[arp->sequenceLength].pitch = globals.keyboardNotes[i]+liveArpeggio.transposeShift;      /* Add the new pitch to the appended note */
                    arp->notesOrdered[arp->sequenceLength].length = 111;
                    arp->notesUnordered[arp->sequenceLength].length = 111;                          /* Give the new note a default length. TEMP */
                }
            }           
        }   
        sortNoteStack(&arp);
    }
EN

回答 1

Stack Overflow用户

发布于 2013-08-05 03:22:43

使用sortNoteStack(&arp),您传递的是指针的地址,而不是结构的地址。您希望传递结构的地址(指针的值)。因此,请使用sortNoteStack(arp)

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18046648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档