首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

DSP中for循环的有关问题

2013-09-28 
DSP中for循环的问题问题是for循环内赋值后打印,竟然与下一个for循环后打印值不同。中间我也没有改变q_temp

DSP中for循环的问题
问题是for循环内赋值后打印,竟然与下一个for循环后打印值不同。中间我也没有改变q_temp的值啊,这是怎么回事啊。
代码如下。  
for (i=b[1];i<b[3]+1;i++)
for (j=b[0];j<b[2]+1;j++)  
 { q_r=(double)(displaybuffer1[i][j*3]/16.0);  
   q_g=(double)(displaybuffer1[i][j*3+1]/16.0);
   q_b=(double)(displaybuffer1[i][j*3+2]/16.0);
   q_temp[i-b[1]][j-b[0]]=(int)(256.0*q_r+16.0*q_g+q_b);
   q= q_temp[i-b[1]][j-b[0]];
   hist[q]= hist[q]+m_wei[i-b[1]][j-b[0]];
   if((i<b[1]+2) & (j<b[0]+2))
   printf("q_temp=%d\n",q_temp[i-b[1]][j-b[0]]);
   }
                   
for (i=b[1];i<b[1]+2;i++)
 for (j=b[0];j<b[0]+2;j++)  
  printf("q_temp=%d\n",q_temp[i-b[1]][j-b[0]]); DSP? for 循环
[解决办法]
先确认i-b[1], j-b[0]会不会溢出q_temp的下标范围。
[解决办法]
两个for循环的范围不同,当然打印值不一样:
for (i=b[1];i<b[3]+1;i++)
for (j=b[0];j<b[2]+1;j++)
...
for (i=b[1];i<b[1]+2;i++)
for (j=b[0];j<b[0]+2;j++)
另外需查看数组的访问是否越界了。

引用:
问题是for循环内赋值后打印,竟然与下一个for循环后打印值不同。中间我也没有改变q_temp的值啊,这是怎么回事啊。
代码如下。  
for (i=b[1];i<b[3]+1;i++)
for (j=b[0];j<b[2]+1;j++)  
 { q_r=(double)(displaybuffer1[i][j*3]/16.0);  
   q_g=(double)(displaybuffer1[i][j*3+1]/16.0);
   q_b=(double)(displaybuffer1[i][j*3+2]/16.0);
   q_temp[i-b[1]][j-b[0]]=(int)(256.0*q_r+16.0*q_g+q_b);
   q= q_temp[i-b[1]][j-b[0]];
   hist[q]= hist[q]+m_wei[i-b[1]][j-b[0]];
   if((i<b[1]+2) & (j<b[0]+2))
   printf("q_temp=%d\n",q_temp[i-b[1]][j-b[0]]);
   }
                   
for (i=b[1];i<b[1]+2;i++)
 for (j=b[0];j<b[0]+2;j++)  
  printf("q_temp=%d\n",q_temp[i-b[1]][j-b[0]]);


引用:
问题是for循环内赋值后打印,竟然与下一个for循环后打印值不同。中间我也没有改变q_temp的值啊,这是怎么回事啊。
代码如下。  
for (i=b[1];i<b[3]+1;i++)
for (j=b[0];j<b[2]+1;j++)  
 { q_r=(double)(displaybuffer1[i][j*3]/16.0);  
   q_g=(double)(displaybuffer1[i][j*3+1]/16.0);
   q_b=(double)(displaybuffer1[i][j*3+2]/16.0);
   q_temp[i-b[1]][j-b[0]]=(int)(256.0*q_r+16.0*q_g+q_b);
   q= q_temp[i-b[1]][j-b[0]];
   hist[q]= hist[q]+m_wei[i-b[1]][j-b[0]];
   if((i<b[1]+2) & (j<b[0]+2))
   printf("q_temp=%d\n",q_temp[i-b[1]][j-b[0]]);
   }
                   
for (i=b[1];i<b[1]+2;i++)
 for (j=b[0];j<b[0]+2;j++)  
  printf("q_temp=%d\n",q_temp[i-b[1]][j-b[0]]);

[解决办法]
To set a breakpoint when a variable q_temp[0][0] changes value 

1.From the Edit menu, click Breakpoints.
2.Click the Data tab of the Breakpoints dialog box.
3.In the Expression text box, type the name of the variable q_temp[0][0].
4.Click OK to set the breakpoint. 

[解决办法]
引用:
To set a breakpoint when a variable q_temp[0][0] changes value 

1.From the Edit menu, click Breakpoints.
2.Click the Data tab of the Breakpoints dialog box.
3.In the Expression text box, type the name of the variable q_temp[0][0].
4.Click OK to set the breakpoint. 

这个是VC6 IDE下的。

帖主学习数据值改变断点正当时!
#include <time.h>
#include <stdlib.h>
#include <windows.h>
int main() {
    int a,b[11];//本来是b[10],为判断哪句越界,故意声明为b[11]

    srand((unsigned int)time(NULL));//按两次F11,等黄色右箭头指向本行时,调试、新建断点、新建数据断点,地址:&b[10],字节计数:4,确定。
    while (1) {//按F5,会停在下面某句,此时a的值为10,b[10]已经被修改为对应0..4之一。


        b[(a=rand()%11)]=0;
        Sleep(100);
        b[(a=rand()%11)]=1;
        Sleep(100);
        b[(a=rand()%11)]=2;
        Sleep(100);
        b[(a=rand()%11)]=3;
        Sleep(100);
        b[(a=rand()%11)]=4;
        Sleep(100);
    }
    return 0;
}


[解决办法]
q_temp=( int**)malloc(n1*sizeof(int)); //第一维 
你的机器上sizeof(int*)是多少?不等于sizeof(int)的话可能会有问题。

热点排行