Altera_Forum
Honored Contributor
13 years agoA big bug?
Hi,
Here is a simple program:# include <stdio.h># include <io.h># include "sys/alt_stdio.h"# include "alt_types.h"# include "system.h" alt_u8 SND[1100]; int main() { int i; int prt1; alt_u8 *p8; alt_u32 *p32; for(i=0;i<100;i++)SND=0;snd[47]=9;
snd[46]=8;
p8=snd+48;
p32=(alt_u32 *)p8;
*p32=0x11223344;
prt1=(int)p32;
i=prt1 & 0x3;
uartprintf("\n\n\n\nsnd48 | 4=(%d:%d),%x,%x,%x,%x,%x,%x,\n",prt1,i,snd[46],snd[47],snd[48],snd[49],snd[50],snd[51]);
for(i=0;i<100;i++)snd=0; SND[47]=9; SND[46]=8; p8=SND+50; p32=(alt_u32 *)p8; *p32=0x11223344; prt1=(int)p32; i=prt1 & 0x3; UartPrintf("\n\n\n\nSND50 | 4=(%d:%d),%x,%x,%x,%x,%x,%x,\n",prt1,i,SND[46],SND[47],SND[48],SND[49],SND[50],SND[51]); return 0; } and the printed results are as following: ___________________________________________ SND48 | 4=(67146460:0),8,9,44,33,22,11, SND50 | 4=(67146462:2),8,9,44,33,22,11, ___________________________________________ while it should be as following: ___________________________________________ SND48 | 4=(67146460:0),8,9,44,33,22,11, SND50 | 4=(67146462:2),8,9,00,00,44,33, ___________________________________________ Is there any person encountered this case? It seems that *P32 only can be used in the case of ((int)p32) % 4 =0, otherwise it will get an error result.