Strange compile error

Started by
3 comments, last by programering 15 years, 4 months ago
I got a unlogical compile error to the following piece of code to save .bmp's in RGBA format:

typedef struct tagBITMAPFILEHEADER { 
  Uint16   bfType; 
  Uint32   bfSize; 
  Uint16   bfReserved1; 
  Uint16   bfReserved2; 
  Uint32   bfOffBits; 
} BITMAPFILEHEADER; 



typedef long FXPT2DOT30;

typedef struct tagCIEXYZ {
  FXPT2DOT30 ciexyzX;
  FXPT2DOT30 ciexyzY;
  FXPT2DOT30 ciexyzZ;
} CIEXYZ;


typedef struct tagCIEXYZTRIPLE {
  CIEXYZ  ciexyzRed;
  CIEXYZ  ciexyzGreen;
  CIEXYZ  ciexyzBlue;
} CIEXYZTRIPLE;


typedef struct tagBITMAPV4HEADER {
	Uint32        bV4Size;
	Sint32        bV4Width;
	Sint32        bV4Height;
	Uint16        bV4Planes;
	Uint16        bV4BitCount;
	Uint32        bV4V4Compression;
	Uint32        bV4SizeImage;
	Sint32        bV4XPelsPerMeter;
	Sint32        bV4YPelsPerMeter;
	Uint32        bV4ClrUsed;
	Uint32        bV4ClrImportant;
	Uint32        bV4RedMask;
	Uint32        bV4GreenMask;
	Uint32        bV4BlueMask;
	Uint32        bV4AlphaMask;
	Uint32        bV4CSType;
	CIEXYZTRIPLE  bV4Endpoints;
	Uint32        bV4GammaRed;
	Uint32        bV4GammaGreen;
	Uint32        bV4GammaBlue;
} BITMAPV4HEADER;


BITMAPFILEHEADER bmpFileHeader;
BITMAPV4HEADER	 bmpV4Header;


bool SaveRGBA32BMP_RW(SDL_Surface *surf, SDL_RWops *dst, bool freedst)
{
	
	if (!surf || !dst || surf->format->BitsPerPixel != 32)
	{
		if (dst && freedst)
			SDL_RWclose(dst);

		return false;
	}
	

	long fp_start = SDL_RWtell(dst);

	// Fill the BITMAPFILEHEADER:
	bmpFileHeader.bfType = 0x4D42;
//	bmpFileHeader.bfMagic[0] = 'B';
//	bmpFileHeader.bfMagic[1] = 'M';
	bmpFileHeader.bfSize = 0;
	bmpFileHeader.bfReserved1 = 0;
	bmpFileHeader.bfReserved2 = 0;
	bmpFileHeader.bfOffBits = 0;
	// Write it:
	SDL_RWwrite(dst,&bmpFileHeader,sizeof(bmpFileHeader),1);

	// Fill the BITMAPV4HEADER:
	bmpV4Header.bV4Size = 108; //sizeof BITMAPV4HEADER;
	bmpV4Header.bV4Width = surf->w;
	bmpV4Header.bV4Height = surf->h;
	bmpV4Header.bV4Planes = 1;
	bmpV4Header.bV4BitCount = 32;
	bmpV4Header.bV4V4Compression = BI_RGB;
	bmpV4Header.bV4SizeImage = surf->pitch * surf->h;
	bmpV4Header.bV4XPelsPerMeter = 0;
	bmpV4Header.bV4YPelsPerMeter = 0;
	bmpV4Header.bV4ClrUsed = 0;
	bmpV4Header.bV4ClrImportant = 0;
	bmpV4Header.bV4RedMask = surf->format->Rmask; // line 198
	bmpV4Header.bV4GreenMask = surf->format->Gmask;
	bmpV4Header.bV4BlueMask = surf->format->Bmask;
	bmpV4Header.bV4AlphaMask = surf->format->Amask;
	bmpV4Header.bV4CSType = 0;
	bmpV4Header.bV4Endpoints.ciexyzRed.ciexyzX = 0;
	bmpV4Header.bV4Endpoints.ciexyzRed.ciexyzY = 0;
	bmpV4Header.bV4Endpoints.ciexyzRed.ciexyzZ = 0;
	bmpV4Header.bV4Endpoints.ciexyzGreen.ciexyzX = 0;
	bmpV4Header.bV4Endpoints.ciexyzGreen.ciexyzY = 0;
	bmpV4Header.bV4Endpoints.ciexyzGreen.ciexyzZ = 0;
	bmpV4Header.bV4Endpoints.ciexyzBlue.ciexyzX = 0;
	bmpV4Header.bV4Endpoints.ciexyzBlue.ciexyzY = 0;
	bmpV4Header.bV4Endpoints.ciexyzBlue.ciexyzZ = 0;
	bmpV4Header.bV4GammaRed = 0;
	bmpV4Header.bV4GammaGreen = 0;
	bmpV4Header.bV4GammaBlue = 0;
	// Write it:
	SDL_RWwrite(dst,&bmpV4Header,sizeof(bmpV4Header),1);

	// Get the offset:
	bmpFileHeader.bfOffBits = SDL_RWtell(dst);

	// Write the pixels:
	SDL_RWwrite(dst,surf->pixels,bmpV4Header.bV4SizeImage,1);

	// Get the file size:
	bmpFileHeader.bfSize = SDL_RWtell(dst);

	// Re-Write the BITMAPFILEHEADER with the new info:
	SDL_RWseek(dst,fp_start,RW_SEEK_SET); // Set the file pointer back.
	SDL_RWwrite(dst,&bmpFileHeader,sizeof(bmpFileHeader),1); // Write it.
	SDL_RWseek(dst,fp_start+bmpFileHeader.bfSize,RW_SEEK_SET); // Set the file pointer back.

	if (freedst)
		SDL_RWclose(dst);

	return true;
}

The error prompt:

Compiling...
rgba.cpp
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(198) : error C2059: syntax error : 'constant'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(199) : error C2039: 'bmpV4Header' : is not a member of 'SDL_PixelFormat'
        c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(199) : error C2039: 'bV4GreenMask' : is not a member of 'SDL_PixelFormat'
        c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(199) : error C2059: syntax error : 'constant'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(200) : error C2039: 'bmpV4Header' : is not a member of 'SDL_PixelFormat'
        c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(200) : error C2039: 'bV4BlueMask' : is not a member of 'SDL_PixelFormat'
        c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(200) : error C2059: syntax error : 'constant'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(201) : error C2039: 'bmpV4Header' : is not a member of 'SDL_PixelFormat'
        c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(201) : error C2039: 'bV4AlphaMask' : is not a member of 'SDL_PixelFormat'
        c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(201) : error C2059: syntax error : 'constant'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(202) : error C2039: 'bmpV4Header' : is not a member of 'SDL_PixelFormat'
        c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(202) : error C2039: 'bV4CSType' : is not a member of 'SDL_PixelFormat'
        c:\program\microsoft visual studio\vc98\include\sdl\sdl_video.h(62) : see declaration of 'SDL_PixelFormat'
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(203) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(203) : error C2228: left of '.ciexyzRed' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(203) : error C2228: left of '.ciexyzX' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(204) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(204) : error C2228: left of '.ciexyzRed' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(204) : error C2228: left of '.ciexyzY' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(205) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(205) : error C2228: left of '.ciexyzRed' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(205) : error C2228: left of '.ciexyzZ' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(206) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(206) : error C2228: left of '.ciexyzGreen' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(206) : error C2228: left of '.ciexyzX' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(207) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(207) : error C2228: left of '.ciexyzGreen' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(207) : error C2228: left of '.ciexyzY' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(208) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(208) : error C2228: left of '.ciexyzGreen' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(208) : error C2228: left of '.ciexyzZ' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(209) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(209) : error C2228: left of '.ciexyzBlue' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(209) : error C2228: left of '.ciexyzX' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(210) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(210) : error C2228: left of '.ciexyzBlue' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(210) : error C2228: left of '.ciexyzY' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(211) : error C2228: left of '.bV4Endpoints' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(211) : error C2228: left of '.ciexyzBlue' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(211) : error C2228: left of '.ciexyzZ' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(212) : error C2228: left of '.bV4GammaRed' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(213) : error C2228: left of '.bV4GammaGreen' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(214) : error C2228: left of '.bV4GammaBlue' must have class/struct/union type
C:\Save\Projects\Programming\RGBA Format\rgba.cpp(222) : error C2228: left of '.bV4SizeImage' must have class/struct/union type
Error executing cl.exe.

RGBA.exe - 43 error(s), 0 warning(s)

This code causes the strange compile errors:

bmpV4Header.bV4RedMask = surf->format->Rmask;
bmpV4Header.bV4GreenMask = surf->format->Gmask;
bmpV4Header.bV4BlueMask = surf->format->Bmask;
bmpV4Header.bV4AlphaMask = surf->format->Amask;
I don't get it; It says that bmpV4Header, bV4RedMask, bV4GreenMask, bV4BlueMask and bV4AlphaMask is not a member of 'SDL_PixelFormat' when I assign the bV4XXXMask members of bmpV4Header with surf->format->Xmask. When I remove the "surf->format->" before the errors disappears. How can this be?
Advertisement
The first line is the only important thing. For some reason Visual C++ drops some variable name out, so you are trying to do something like
bmpV4Header.bV4RedMask = surf->format->bmpV4Header.bV4CSType = 0;


Are you sure you are not including or linking some file that has bV4RedMask, Rmask, bV4GreenMask, Gmask, bV4BlueMask, Bmask, bV4AlphaMask or Amask defined as a constant?
It's this topic.

It must been caused by this coming before:
#if SDL_BYTEORDER == SDL_LIL_ENDIAN#	define Rmask 0x000000FF#	define Gmask 0x0000FF00#	define Bmask 0x00FF0000#	define Amask 0xFF000000/*#	define Rshift 0#	define Gshift 8#	define Bshift 16#	define Ashift 24*/#else#	define Rmask 0xFF000000#	define Gmask 0x00FF0000#	define Bmask 0x0000FF00#	define Amask 0x000000FF/*#	define Rshift 24#	define Gshift 16#	define Bshift 8#	define Ashift 0*/#endifSDL_Surface *ConvRGBA32(SDL_Surface *orig){	int width = orig->w;	int height = orig->h;	SDL_Surface *rgba = SDL_CreateRGBSurface(SDL_SWSURFACE,width,height,32,Rmask,Gmask,Bmask,Amask);	Uint32 npixels = width * height;	SDL_PixelFormat *format = orig->format;	SDL_Palette *palette = format->palette;	SDL_Color *entry;	Uint8 bpp = format->BytesPerPixel;	Uint32 *dstpix = (Uint32 *)rgba->pixels;	Uint8 *srcpix = (Uint8 *)orig->pixels;	Uint8 r, g, b, a;	Uint32 color;	for (Uint32 i = 0; i < npixels; i++)	{		if (format->BitsPerPixel == 8 && palette)		{			entry = palette->colors + *srcpix;			r = entry->r;			g = entry->g;			b = entry->b;			color = SDL_MapRGB(format,r,g,b);		}		else		{			color = *(Uint32 *)srcpix;			SDL_GetRGB(color,format,&r,&g,&b);		}		if (color == format->colorkey)			a = 0xC0;		else			a = 0xff;		*dstpix++ = SDL_MapRGBA(rgba->format,r,g,b,a);		srcpix += bpp;	//	*dstpix++ = 0xFF000000;	//0x22CCFF99;	//0xCC00FFFF; //0xFFFFFFFF;	}	return rgba;}

I've put it after now and those errors are gone.
Quote:Original post by programering
It's this topic.

It must been caused by this coming before:
*** Source Snippet Removed ***
I've put it after now and those errors are gone.


This is why you use real constants to define constants, instead of automated text substitution hacks (i.e. the preprocessor).

#if SDL_BYTEORDER == SDL_LIL_ENDIANconst int Rmask = 0x000000FF;const int Gmask = 0x0000FF00;// etc.#else// etc.#endifbmpV4Header.bV4RedMask = surf->format->Rmask;// works fine, because the 'Rmask' member of surf->format is a different thing// from the 'Rmask' global variable.


Although you really might want to reconsider your variable names. And actually, the code that requires such constants ought to be fairly tightly localized, so...
Quote:Original post by Zahlman
Quote:Original post by programering
It's this topic.

It must been caused by this coming before:
*** Source Snippet Removed ***
I've put it after now and those errors are gone.


This is why you use real constants to define constants, instead of automated text substitution hacks (i.e. the preprocessor).

#if SDL_BYTEORDER == SDL_LIL_ENDIANconst int Rmask = 0x000000FF;const int Gmask = 0x0000FF00;// etc.#else// etc.#endifbmpV4Header.bV4RedMask = surf->format->Rmask;// works fine, because the 'Rmask' member of surf->format is a different thing// from the 'Rmask' global variable.


Ofcoarse. It was so first from the one I copied that code.

Quote:
Although you really might want to reconsider your variable names. And actually, the code that requires such constants ought to be fairly tightly localized, so...
What do you mean?

This topic is closed to new replies.

Advertisement