下面的函数populateArpeggioArray接受一个指向包含几个成员的类型定义结构的指针,这些成员的身份不一定与我遇到的问题相关。在将指向结构的指针传递给函数sortNoteStack之前,populateArpeggioArray应该对结构的内部元素执行一些操作。
我发现sortNoteStack从不对该结构进行操作,因为在将更改后的值传递给sortNoteStack之前,populateArpeggioArray会在某个时刻更改指向该结构的指针的值。
据我所知,代码的格式似乎是正确的,在结构元素上执行的所有操作都有正确的指针取消引用。据我所见,没有一行代码能够修改指向结构的指针的值。使用const前缀声明结构没有任何帮助,因为它的成员也因此锁定为固定值。
我对这可能是模拟器的问题,而不是代码的问题持开放态度,但如果我写的代码有一些潜在的问题,我当然想知道我做错了什么。
谢谢你的帮助。
-Nick
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);
}发布于 2013-08-05 03:22:43
使用sortNoteStack(&arp),您传递的是指针的地址,而不是结构的地址。您希望传递结构的地址(指针的值)。因此,请使用sortNoteStack(arp)。
https://stackoverflow.com/questions/18046648
复制相似问题