typedef struct { unsigned short *Buf; unsigned short *PrtbufVal; unsigned char BufLen; } AdcTypeS; int main(void) { static unsigned char temp = 0; static unsigned char t = 0; static unsigned char i = 0; unsigned long a[56] = {1,2,3,4,5,6,7.8,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28.29,30,31,32,33,34,35,36,37,38,39,40,41,46,43,44,45,46,47,48,49,50,51,52,53,54,55}; unsigned long *p; p = a; unsigned short aBuf[10]; unsigned short bBuf[11]; unsigned short cBuf[12]; unsigned short aBufcn = 0; unsigned short bBufCnt = 0; unsigned short cBufCnt = 0; AdcTypeS adc[3] = { {aBuf, &aBufcn, 10}, {bBuf, &bBufCnt, 11}, {cBuf, &cBufCnt, 12} }; while (++t <= 56) { if ((adc[temp].PrtbufVal)++ >= adc[temp].BufLen) { *adc[temp].PrtbufVal = 0; } adc[temp].Buf[*adc[temp].PrtbufVal] = (unsigned short)p[i]; i++; if (++temp >= 3) { temp = 0; } printf("%d, %lu, %d, %lu\n", temp, *adc[temp].PrtbufVal, adc[temp].Buf[adc[temp].PrtbufVal], p[i]); } return 0; } 这段代码,当
时间: 2023-09-24 09:12:07 浏览: 89
Keil MDK-ARM各种数据类型占用的字节数 char short int float double
5星 · 资源好评率100%
这段代码执行时,会依次将数组a的元素赋值给adc数组中的Buf,并且循环打印出temp、*adc[temp].PrtbufVal、adc[temp].Buf[adc[temp].PrtbufVal]和p[i]的值。根据代码的逻辑,temp的值会在0、1、2之间循环,i的值会从0递增到55,所以总共会执行56次循环。在每次循环中,会根据temp的值选择不同的adc元素进行操作。具体的操作为,将p[i]的值赋给adc[temp].Buf[*adc[temp].PrtbufVal],然后增加*adc[temp].PrtbufVal的值,如果超过了adc[temp].BufLen的大小,则将*adc[temp].PrtbufVal的值重置为0。
最后,会打印出temp、*adc[temp].PrtbufVal、adc[temp].Buf[adc[temp].PrtbufVal]和p[i]的值。
阅读全文