sdl - C primary expressions - Is it primary expression or not? -
i'm using basic sdl program learn print screen.
i following error when run application:
error: expected primary expression before '=' token"
#include "sdl.h" #include <stdio.h> #define window using namespace std; const int screen_width = 640; const int screen_height = 480; int main( int argc, char* args[] ) { sdl_surface* screensurface =null; if( sdl_init( sdl_init_video ) < 0 ) { printf( "sdl not initialize! sdl_error: %s\n",sdl_geterror() ); } else { window = sdl_createwindow( "sdl tutorial", sdl_windowpos_undefined, sdl_windowpos_undefined, screen_width, screen_height, sdl_window_shown ); } if(window==null) { window = sdl_createwindow( "sdl tutorial", sdl_windowpos_undefined, sdl_windowpos_undefined, screen_width, screen_height, sdl_window_shown ); } }
the preprocessor simple, when has macro replaces macro as is.
for example if have
#define window
then preprocessor replace occurrences of symbol windows
nothing!
so statement
window = sdl_createwindow(...);
it after preprocessing
= sdl_createwindow(...);
that's hardly valid code.
if intend window
variable, pointer sdl_window
, should define such:
sdl_window *window;
and remove preprocessor macro.
i agree terminology confusing here. use preprocessor define macros, , can define variables, structures, functions etc. can declare variables, structures, functions etc.
the preprocessor sounds like. used separate program read source file, did processing on (like macro replacement , include file inclusion) , spat out temporary file compiler used. these days preprocessor built compiler, , run @ stage part of complete compilation process. compilers allow output preprocessed source at, suggest try code. macros defined preprocessor not in source fed compiler, lines removed preprocessor.
then comes definition of variables etc. different definition of preprocessor macros. variable definition tells compilers "here variable name this-and-that, of type, please allocate memory store variable".
a variable declaration similar definition, tells compiler "there variable named this-and-that, of specific type, , exists somewhere".
variables can both declared , defined @ same time, example
void function(void) { int a; // declares , defines variable ... }
Comments
Post a Comment