I have a function which takes an array of SDL_Rect (which is a data structure containing four integers, x, y, h and w), and assigns values to the data members. However, when I try to compile, each line generates the error "error C2059: syntax error : '='".

int main()
{
     SDL_Rect clips[ 4 ];
     set_clips( clips );
}

//I get the error in this function on every line
void set_clips( SDL_Rect *clips )
{
    //CLIP_MOUSEOVER and the others are defined to 0, 1, 2, and 3 using #define
    clips[ CLIP_MOUSEOVER ]->x = 0;
    clips[ CLIP_MOUSEOVER ]->y = 0;
    clips[ CLIP_MOUSEOVER ]->w = 320;
    clips[ CLIP_MOUSEOVER ]->h = 240;

    clips[ CLIP_MOUSEOUT ]->x = 320;
    clips[ CLIP_MOUSEOUT ]->y = 0;
    clips[ CLIP_MOUSEOUT ]->w = 320;
    clips[ CLIP_MOUSEOUT ]->h = 240;

    clips[ CLIP_MOUSEDOWN ]->x = 0;
    clips[ CLIP_MOUSEDOWN ]->y = 240;
    clips[ CLIP_MOUSEDOWN ]->w = 320;
    clips[ CLIP_MOUSEDOWN ]->h = 240;
    
    clips[ CLIP_MOUSEUP ]->x = 320;
    clips[ CLIP_MOUSEUP ]->y = 240;
    clips[ CLIP_MOUSEUP ]->w = 320;
    clips[ CLIP_MOUSEUP ]->h = 240;    
}

I've been trying to figure it out for hours. Any idea what causes it? (I'm willing to bet it's something really stupid).

Recommended Answers

All 8 Replies

I have a function which takes an array of SDL_Rect (which is a data structure containing four integers, x, y, h and w), and assigns values to the data members. However, when I try to compile, each line generates the error "error C2059: syntax error : '='".

int main()
{
     SDL_Rect clips[ 4 ];
     set_clips( clips );
}

//I get the error in this function on every line
void set_clips( SDL_Rect *clips )
{
    //CLIP_MOUSEOVER and the others are defined to 0, 1, 2, and 3 using #define
    clips[ CLIP_MOUSEOVER ]->x = 0;
    clips[ CLIP_MOUSEOVER ]->y = 0;
    clips[ CLIP_MOUSEOVER ]->w = 320;
    clips[ CLIP_MOUSEOVER ]->h = 240;

    clips[ CLIP_MOUSEOUT ]->x = 320;
    clips[ CLIP_MOUSEOUT ]->y = 0;
    clips[ CLIP_MOUSEOUT ]->w = 320;
    clips[ CLIP_MOUSEOUT ]->h = 240;

    clips[ CLIP_MOUSEDOWN ]->x = 0;
    clips[ CLIP_MOUSEDOWN ]->y = 240;
    clips[ CLIP_MOUSEDOWN ]->w = 320;
    clips[ CLIP_MOUSEDOWN ]->h = 240;
    
    clips[ CLIP_MOUSEUP ]->x = 320;
    clips[ CLIP_MOUSEUP ]->y = 240;
    clips[ CLIP_MOUSEUP ]->w = 320;
    clips[ CLIP_MOUSEUP ]->h = 240;    
}

I've been trying to figure it out for hours. Any idea what causes it? (I'm willing to bet it's something really stupid).

I got a different error from you. What's your exact error message. However, when I changed the -> to a period it worked for me. the program below compiled for me. clips[0], clips[1], clips[2], clips[3] are of type SDL_Rect, not SDL_Rect*, so you don't want the -> operator. The program below compiled for me.

#define CLIP_MOUSEOVER 0
#define CLIP_MOUSEOUT 1
#define CLIP_MOUSEDOWN 2
#define CLIP_MOUSEUP 3

struct SDL_Rect
{
       int x;
       int y;
       int w;
       int h;
};


void set_clips( SDL_Rect * clips );


int main()
{
     SDL_Rect clips[4];
     set_clips( clips );
     return 0;
}

//I get the error in this function on every line
void set_clips( SDL_Rect * clips )
{
    //CLIP_MOUSEOVER and the others are defined to 0, 1, 2, and 3 using #define
    
    clips[ CLIP_MOUSEOVER ].x = 0;
    clips[ CLIP_MOUSEOVER ].y = 0;
    clips[ CLIP_MOUSEOVER ].w = 320;
    clips[ CLIP_MOUSEOVER ].h = 240;

    clips[ CLIP_MOUSEOUT ].x = 320;
    clips[ CLIP_MOUSEOUT ].y = 0;
    clips[ CLIP_MOUSEOUT ].w = 320;
    clips[ CLIP_MOUSEOUT ].h = 240;

    clips[ CLIP_MOUSEDOWN ].x = 0;
    clips[ CLIP_MOUSEDOWN ].y = 240;
    clips[ CLIP_MOUSEDOWN ].w = 320;
    clips[ CLIP_MOUSEDOWN ].h = 240;
    
    clips[ CLIP_MOUSEUP ].x = 320;
    clips[ CLIP_MOUSEUP ].y = 240;
    clips[ CLIP_MOUSEUP ].w = 320;
    clips[ CLIP_MOUSEUP ].h = 240;    
}

Your code worked for me too, so I replaced the '->' with '.', but was still getting an error. I was messing around with my code for a while, and finally found that replacing the CLIP_MOUSE stuff with actual numbers worked. So, I'm wondering now, why would

clips[ 0 ].x = 240

work, but not

#define NUMBER 0
clips[ NUMBER ].x = 240

I thought #define NUMBER 0 would be the exact same thing as putting in a 0 yourself ?

Also, I should've mentioned this earlier, but SDL_Rect comes from an outside library. The definition is:

typedef struct{
  Sint16 x, y;
  Uint16 w, h;
} SDL_Rect;
#define NUMBER 0
clips[ NUMBER ].x = 240

Would you mind posting the error message(s) that you get using the above non-working construct? And what is your compiler?

struct SDL_Rect is define by SDL.h
so if you want to use it just include the header...
anyway SLD need main to have int main(int argc, char **argv)
this compile for me ;)

#include <SDL/SDL.h>

#define CLIP_MOUSEOVER 0
#define CLIP_MOUSEOUT 1
#define CLIP_MOUSEDOWN 2
#define CLIP_MOUSEUP 3

//struct SDL_Rect
//{
//       int x;
//       int y;
//       int w;
//       int h;
//};


void set_clips(SDL_Rect * clips);

int main(int argc, char **argv) {
	SDL_Rect clips[4];
	set_clips(clips);
	return 0;
}

//I get the error in this function on every line
void set_clips(SDL_Rect * clips) {
	//CLIP_MOUSEOVER and the others are defined to 0, 1, 2, and 3 using #define

	clips[ CLIP_MOUSEOVER ].x = 0;
	clips[ CLIP_MOUSEOVER ].y = 0;
	clips[ CLIP_MOUSEOVER ].w = 320;
	clips[ CLIP_MOUSEOVER ].h = 240;

	clips[ CLIP_MOUSEOUT ].x = 320;
	clips[ CLIP_MOUSEOUT ].y = 0;
	clips[ CLIP_MOUSEOUT ].w = 320;
	clips[ CLIP_MOUSEOUT ].h = 240;

	clips[ CLIP_MOUSEDOWN ].x = 0;
	clips[ CLIP_MOUSEDOWN ].y = 240;
	clips[ CLIP_MOUSEDOWN ].w = 320;
	clips[ CLIP_MOUSEDOWN ].h = 240;

	clips[ CLIP_MOUSEUP ].x = 320;
	clips[ CLIP_MOUSEUP ].y = 240;
	clips[ CLIP_MOUSEUP ].w = 320;
	clips[ CLIP_MOUSEUP ].h = 240;
}

struct SDL_Rect is define by SDL.h
so if you want to use it just include the header...
anyway SLD need main to have int main(int argc, char **argv)
this compile for me ;)

#include <SDL/SDL.h>

#define CLIP_MOUSEOVER 0
#define CLIP_MOUSEOUT 1
#define CLIP_MOUSEDOWN 2
#define CLIP_MOUSEUP 3

//struct SDL_Rect
//{
//       int x;
//       int y;
//       int w;
//       int h;
//};


void set_clips(SDL_Rect * clips);

int main(int argc, char **argv) {
	SDL_Rect clips[4];
	set_clips(clips);
	return 0;
}

//I get the error in this function on every line
void set_clips(SDL_Rect * clips) {
	//CLIP_MOUSEOVER and the others are defined to 0, 1, 2, and 3 using #define

	clips[ CLIP_MOUSEOVER ].x = 0;
	clips[ CLIP_MOUSEOVER ].y = 0;
	clips[ CLIP_MOUSEOVER ].w = 320;
	clips[ CLIP_MOUSEOVER ].h = 240;

	clips[ CLIP_MOUSEOUT ].x = 320;
	clips[ CLIP_MOUSEOUT ].y = 0;
	clips[ CLIP_MOUSEOUT ].w = 320;
	clips[ CLIP_MOUSEOUT ].h = 240;

	clips[ CLIP_MOUSEDOWN ].x = 0;
	clips[ CLIP_MOUSEDOWN ].y = 240;
	clips[ CLIP_MOUSEDOWN ].w = 320;
	clips[ CLIP_MOUSEDOWN ].h = 240;

	clips[ CLIP_MOUSEUP ].x = 320;
	clips[ CLIP_MOUSEUP ].y = 240;
	clips[ CLIP_MOUSEUP ].w = 320;
	clips[ CLIP_MOUSEUP ].h = 240;
}

That code compiled for me as well, but I'm still having problems. I created a new project and changed the compiler settings a bit to include the SDL library, then put in the code:

#include <SDL/SDL.h>

#define CLIP_MOUSEOUT = 0
#define CLIP_MOUSEOVER = 1
#define CLIP_MOUSEDOWN = 2
#define CLIP_MOUSEUP = 3

void set_clips( SDL_Rect* );

int main( int argc, char **argv )
{
	SDL_Rect clips[ 4 ];
	set_clips( clips );	
	return 0;
}

void set_clips( SDL_Rect *clips )
{
	clips[ CLIP_MOUSEOUT ].x = 0;
    clips[ CLIP_MOUSEOUT ].y = 0;
    clips[ CLIP_MOUSEOUT ].w = 320;
    clips[ CLIP_MOUSEOUT ].h = 240;

    clips[ CLIP_MOUSEOVER ].x = 320;
    clips[ CLIP_MOUSEOVER ].y = 0;
    clips[ CLIP_MOUSEOVER ].w = 320;
    clips[ CLIP_MOUSEOVER ].h = 240;

    clips[ CLIP_MOUSEDOWN ].x = 0;
    clips[ CLIP_MOUSEDOWN ].y = 240;
    clips[ CLIP_MOUSEDOWN ].w = 320;
    clips[ CLIP_MOUSEDOWN ].h = 240;
    
    clips[ CLIP_MOUSEUP ].x = 320;
    clips[ CLIP_MOUSEUP ].y = 240;
    clips[ CLIP_MOUSEUP ].w = 320;
    clips[ CLIP_MOUSEUP ].h = 240;    
}

I still get the compiler errors:

Compiling...
SDL_Test.cpp
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(19) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(20) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(21) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(22) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(24) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(25) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(26) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(27) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(29) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(30) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(31) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(32) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(34) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(35) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(36) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(37) : error C2059: syntax error : '='

The thing I find really odd, is that this will compile (I don't see any difference with this from the code above):

#include <SDL/SDL.h>

#define CLIP_MOUSEOUT 0
#define CLIP_MOUSEOVER 1
#define CLIP_MOUSEDOWN 2
#define CLIP_MOUSEUP 3

void set_clips( SDL_Rect* );

int main( int argc, char **argv ) 
{
	SDL_Rect clips[ 4 ];
	set_clips( clips );
	return 0;
}

void set_clips( SDL_Rect *clips ) 
{
	clips[ CLIP_MOUSEOUT ].x = 0;
	clips[ CLIP_MOUSEOUT ].y = 0;
	clips[ CLIP_MOUSEOUT ].w = 320;
	clips[ CLIP_MOUSEOUT ].h = 240;

	clips[ CLIP_MOUSEOVER ].x = 320;
	clips[ CLIP_MOUSEOVER ].y = 0;
	clips[ CLIP_MOUSEOVER ].w = 320;
	clips[ CLIP_MOUSEOVER ].h = 240;

	clips[ CLIP_MOUSEDOWN ].x = 0;
	clips[ CLIP_MOUSEDOWN ].y = 240;
	clips[ CLIP_MOUSEDOWN ].w = 320;
	clips[ CLIP_MOUSEDOWN ].h = 240;

	clips[ CLIP_MOUSEUP ].x = 320;
	clips[ CLIP_MOUSEUP ].y = 240;
	clips[ CLIP_MOUSEUP ].w = 320;
	clips[ CLIP_MOUSEUP ].h = 240;
}

I'm using Visual C++ Express to compile this. The compiler settings I changed were: C++->Code Generation->Runtime library (changed it from /MDd to /MD); Linker->Input->Additional dependencies (added SDL.lib SDLmain.lib); and Linker->System->SubSystem (changed from console to windows). Also, if you want to view the build log, I put it on a webpage: http://www.geocities.com/evan_maurice/buildlog.html.

It is #define CLIP_MOUSEOUT 0 instead of #define CLIP_MOUSEOUT = 0

That code compiled for me as well, but I'm still having problems. I created a new project and changed the compiler settings a bit to include the SDL library, then put in the code:

#include <SDL/SDL.h>

#define CLIP_MOUSEOUT = 0;
#define CLIP_MOUSEOVER = 1;
#define CLIP_MOUSEDOWN = 2;
#define CLIP_MOUSEUP = 3;

void set_clips( SDL_Rect* );

int main( int argc, char **argv )
{
	SDL_Rect clips[ 4 ];
	set_clips( clips );	
	return 0;
}

void set_clips( SDL_Rect *clips )
{
	clips[ CLIP_MOUSEOUT ].x = 0;
    clips[ CLIP_MOUSEOUT ].y = 0;
    clips[ CLIP_MOUSEOUT ].w = 320;
    clips[ CLIP_MOUSEOUT ].h = 240;

    clips[ CLIP_MOUSEOVER ].x = 320;
    clips[ CLIP_MOUSEOVER ].y = 0;
    clips[ CLIP_MOUSEOVER ].w = 320;
    clips[ CLIP_MOUSEOVER ].h = 240;

    clips[ CLIP_MOUSEDOWN ].x = 0;
    clips[ CLIP_MOUSEDOWN ].y = 240;
    clips[ CLIP_MOUSEDOWN ].w = 320;
    clips[ CLIP_MOUSEDOWN ].h = 240;
    
    clips[ CLIP_MOUSEUP ].x = 320;
    clips[ CLIP_MOUSEUP ].y = 240;
    clips[ CLIP_MOUSEUP ].w = 320;
    clips[ CLIP_MOUSEUP ].h = 240;    
}

I still get the compiler errors:

Compiling...
SDL_Test.cpp
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(19) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(20) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(21) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(22) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(24) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(25) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(26) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(27) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(29) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(30) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(31) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(32) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(34) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(35) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(36) : error C2059: syntax error : '='
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_test\sdl_test\sdl_test.cpp(37) : error C2059: syntax error : '='

The thing I find really odd, is that this will compile (I don't see any difference with this from the code above):

#include <SDL/SDL.h>

#define CLIP_MOUSEOUT 0
#define CLIP_MOUSEOVER 1
#define CLIP_MOUSEDOWN 2
#define CLIP_MOUSEUP 3

void set_clips( SDL_Rect* );

int main( int argc, char **argv ) 
{
	SDL_Rect clips[ 4 ];
	set_clips( clips );
	return 0;
}

void set_clips( SDL_Rect *clips ) 
{
	clips[ CLIP_MOUSEOUT ].x = 0;
	clips[ CLIP_MOUSEOUT ].y = 0;
	clips[ CLIP_MOUSEOUT ].w = 320;
	clips[ CLIP_MOUSEOUT ].h = 240;

	clips[ CLIP_MOUSEOVER ].x = 320;
	clips[ CLIP_MOUSEOVER ].y = 0;
	clips[ CLIP_MOUSEOVER ].w = 320;
	clips[ CLIP_MOUSEOVER ].h = 240;

	clips[ CLIP_MOUSEDOWN ].x = 0;
	clips[ CLIP_MOUSEDOWN ].y = 240;
	clips[ CLIP_MOUSEDOWN ].w = 320;
	clips[ CLIP_MOUSEDOWN ].h = 240;

	clips[ CLIP_MOUSEUP ].x = 320;
	clips[ CLIP_MOUSEUP ].y = 240;
	clips[ CLIP_MOUSEUP ].w = 320;
	clips[ CLIP_MOUSEUP ].h = 240;
}

I'm using Visual C++ Express to compile this. The compiler settings I changed were: C++->Code Generation->Runtime library (changed it from /MDd to /MD); Linker->Input->Additional dependencies (added SDL.lib SDLmain.lib); and Linker->System->SubSystem (changed from console to windows). Also, if you want to view the build log, I put it on a webpage: http://www.geocities.com/evan_maurice/buildlog.html.

It's a syntax issue:

#define CLIP_MOUSEOUT = 0
#define CLIP_MOUSEOVER = 1
#define CLIP_MOUSEDOWN = 2
#define CLIP_MOUSEUP = 3

The above won't compile. Take the equals signs out and it will. The above code is NOT the same as code like this:

int CLIP_MOUSEOUT = 0;
int  CLIP_MOUSEOVER = 1;
int  CLIP_MOUSEDOWN = 2;
int  CLIP_MOUSEUP = 3;

This will compile. If you use #define with the equals sign, it won't. The reason is that in the above example (without #define), four varaibles are being created and they are integers. If you use the #define, all that happens is a big cut-and-paste. The pre-compiler just substitutes 0 from CLIP_MOUSEOUT, 1 for CLIP_MOUSEOVER, etc., just like you do in your word processor. Thus the = sign doesn't have the same meaning when you use it with #define, so leave the = sign off when you use #define.

Thanks for the help guys. I knew it was something stupid.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.