在c文档中C2143问题出现的一种方式及解决方法

在vs2008编译环境中,但将变量或指针以以下方法定义是会出现“ error C2143: syntax error : missing ';' before 'type'”的问题;

见如下代码:

int YUV422ToRGB( unsigned char* yuvdata,int width,int height,int channel, unsigned char* rgb)
{
	int	col,row;
	int u,v;
	int r,b,g;
	

	int ImgSize = width*height;

	int  rgbstep = width*channel;

	int biWide =  rgbstep % 4;

	if (biWide == 0)
	{
		rgbstep =   rgbstep + biWide;
	}
	else
	{
		rgbstep =   rgbstep + 4 - biWide;
	}

	unsigned char *pY;//C2143
	unsigned char *pVU;//C2143
	unsigned char *pR, *pG, *pB;//C2143

	pY = yuvdata;                        //y分量地址// 
	pVU = yuvdata + ImgSize;            //vu分量地址// 

	for (row=0; row<height; row++)
	{
		pB = rgb + rgbstep*row;
		pG = rgb + rgbstep*row + 1;
		pR = rgb + rgbstep*row + 2;

		for (col=0; col<width; col++)
		{

			v=*pVU - 128;
			u=*(pVU+1) - 128;

			r = *pY + v + (v>>2) + (v>>3) + (v>>5);

			b = *pY + u + (u>>1) + (u>>2) + (u>>6); 

			g = *pY + *pY - ((b+r-u)>>1) - ((u+v)>>5); 

			*pR = r < 0 ? 0 : (r > 255 ? 255 : r); 
			*pG = g < 0 ? 0 : (g > 255 ? 255 : g); 
			*pB = b < 0 ? 0 : (b > 255 ? 255 : b); 

			pR += 3;
			pB += 3;
			pG += 3;

			pY++;

			if (col%2 != 0)
			{
				pVU += 2;
			}
		}
	}

	return 0;
}

解决上述问题,可将指针的位置放到函数前面定义,代码如下: 
int YUV422ToRGB( unsigned char* yuvdata,int width,int height,int channel, unsigned char* rgb)
{
	int	col,row;
	int u,v;
	int r,b,g;
	unsigned char *pY;//OK
	unsigned char *pVU;//OK
	unsigned char *pR, *pG, *pB;//OK

	int ImgSize = width*height;

	int  rgbstep = width*channel;

	int biWide =  rgbstep % 4;

	if (biWide == 0)
	{
		rgbstep =   rgbstep + biWide;
	}
	else
	{
		rgbstep =   rgbstep + 4 - biWide;
	}

	

	pY = yuvdata;                        //y分量地址// 
	pVU = yuvdata + ImgSize;            //vu分量地址// 

	for (row=0; row<height; row++)
	{
		pB = rgb + rgbstep*row;
		pG = rgb + rgbstep*row + 1;
		pR = rgb + rgbstep*row + 2;

		for (col=0; col<width; col++)
		{

			v=*pVU - 128;
			u=*(pVU+1) - 128;

			r = *pY + v + (v>>2) + (v>>3) + (v>>5);

			b = *pY + u + (u>>1) + (u>>2) + (u>>6); 

			g = *pY + *pY - ((b+r-u)>>1) - ((u+v)>>5); 

			*pR = r < 0 ? 0 : (r > 255 ? 255 : r); 
			*pG = g < 0 ? 0 : (g > 255 ? 255 : g); 
			*pB = b < 0 ? 0 : (b > 255 ? 255 : b); 

			pR += 3;
			pB += 3;
			pG += 3;

			pY++;

			if (col%2 != 0)
			{
				pVU += 2;
			}
		}
	}

	return 0;

}



具体在这种里出现C2143的原因,本人还没有搞清楚,核查MSDN也没有找到具体问题的解释,有网友知道可留言,不胜感谢。





   

你可能感兴趣的:(c,文档)