When I run "gcc sdltest.c -o sdltest sdl-config --cflags --libs sdl" I get the error below…
Usage: sdl-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--libs] [--cflags]
sdlinit.c: In function `main':
sdlinit.c:13: parse error before `*'
sdlinit.c:14: `screen' undeclared (first use in this function)
sdlinit.c:14: (Each undeclared identifier is reported only once
sdlinit.c:14: for each function it appears in.)
Also, you’re calling ‘sdl-config’ with an unknown argument (“sdl” after
"–libs"), hence this Usage error…
sdlinit.c: In function main': sdlinit.c:13: parse error before*’
(See above )
sdlinit.c:14: `screen’ undeclared (first use in this function)
sdlinit.c:14: (Each undeclared identifier is reported only once
sdlinit.c:14: for each function it appears in.)
(Caused by the above parse error)
-bill!On Mon, Feb 25, 2002 at 06:14:17PM +0000, Darrell Blake wrote:
Another issue I’ve sometimes seen with gcc is that they want you to
declare your variables before anything else is done, so you may want to
move that ‘SDL_Surface *screen;’ to the beginning of main(). Not
entirely sure of the reason for this, I never felt like looking it up.–
Michael Vieths
Foeclan at Visi.com
On 25 Feb 2002, Darrell Blake wrote:
Hi,
Can anyone tell me why the program below doesn’t compile?
SDL_Surface *screen;
screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
if ( screen == NULL )
{
fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError());
exit(1);
}
}
When I run "gcc sdltest.c -o sdltest sdl-config --cflags --libs sdl" I get the error below…
Usage: sdl-config [–prefix[=DIR]] [–exec-prefix[=DIR]] [–version] [–libs] [–cflags]
sdlinit.c: In function main': sdlinit.c:13: parse error before*‘
sdlinit.c:14: `screen’ undeclared (first use in this function)
sdlinit.c:14: (Each undeclared identifier is reported only once
sdlinit.c:14: for each function it appears in.)
SDL_Surface *screen;
screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
if ( screen == NULL )
{
fprintf(stderr, "Unable to set 640x480 video: %s\n",
SDL_GetError()); exit(1);
}
}
When I run "gcc sdltest.c -o sdltest sdl-config --cflags --libs sdl"
I get the error below…
Usage: sdl-config [–prefix[=DIR]] [–exec-prefix[=DIR]] [–version]
[–libs] [–cflags] sdlinit.c: In function main': sdlinit.c:13: parse error before*‘
sdlinit.c:14: `screen’ undeclared (first use in this function)
sdlinit.c:14: (Each undeclared identifier is reported only once
sdlinit.c:14: for each function it appears in.)
I’ve compiled your code sucessfully under win32 with dev-c++, but you have
forgotten the return type of main(it’s the only one thing I’ve changed).
So, the problem might be in the command line for compiling your project?
SDL_Surface *screen;
screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
if ( screen == NULL )
{
fprintf(stderr, “Unable to set 640x480 video: %s\n”,
SDL_GetError());
exit(1);
}
}
When I run "gcc sdltest.c -o sdltest sdl-config --cflags --libs sdl" I
get the error below…
Usage: sdl-config [–prefix[=DIR]] [–exec-prefix[=DIR]] [–version]
[–libs] [–cflags]
sdlinit.c: In function main': sdlinit.c:13: parse error before*‘
sdlinit.c:14: `screen’ undeclared (first use in this function)
sdlinit.c:14: (Each undeclared identifier is reported only once
sdlinit.c:14: for each function it appears in.)
Can anyone help?
Darrell
GCC is a C compiler, the above code is not legal C. It is legal C++ however
(as far as I can tell) so it should compile with G++. To make it legal C (to
compile with GCC) move the SDL_Surface *screen; line to the top of the main
function. C++ allows “inline variables” (not sure if this is the right
term), in C you must specify variables at the top of a function or at the
global scope.
No. It’s just because he’s using a C compiler, not a C++ compiler.
In C++, I believe you can delare new variables int i; wherever you
char c; want float f;
-bill!On Mon, Feb 25, 2002 at 01:32:25PM -0500, Paflecanif at aol.com wrote:
Hello,
I’ve compiled your code sucessfully under win32 with dev-c++, but you have
forgotten the return type of main(it’s the only one thing I’ve changed).
So, the problem might be in the command line for compiling your project?
SDL_Surface *screen;
screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
if ( screen == NULL )
{
fprintf(stderr, “Unable to set 640x480 video: %s\n”,
SDL_GetError());
exit(1);
}
}
When I run "gcc sdltest.c -o sdltest sdl-config --cflags --libs sdl" I
get the error below…
Usage: sdl-config [–prefix[=DIR]] [–exec-prefix[=DIR]] [–version]
[–libs] [–cflags]> sdlinit.c: In function main': sdlinit.c:13: parse error before*‘
sdlinit.c:14: `screen’ undeclared (first use in this function)
sdlinit.c:14: (Each undeclared identifier is reported only once
sdlinit.c:14: for each function it appears in.)
GCC is a C compiler, the above code is not legal C. It is legal C++ however
GCC is the GNU Compiler Collection.
It currently contains compilers for C,C++,Fortran,Java and others.
So it’s not C.
(as far as I can tell) so it should compile with G++. To make it legal C (to
The gcc frontend decides by file-endings how sources should be compiled.
the g++ frontend therefore is just to let the compiler interprete the
source as c++ code independently on the file-ending.
compile with GCC) move the SDL_Surface *screen; line to the top of the main
function. C++ allows “inline variables” (not sure if this is the right
term), in C you must specify variables at the top of a function or at the
global scope.
compile with GCC) move the SDL_Surface *screen; line to the top of the
main
function. C++ allows “inline variables” (not sure if this is the right
term), in C you must specify variables at the top of a function or at
the
global scope.
Also not true. In C variables must be declared at the beginning of the
local scope or
in global space. It has nothing to do with functions per se.
int main ()
{
int i = 0;
printf ("…");/* whatever/*
{
int j = 0;
}
}
thats also legal in C last time I checked.>> Dirk Gerrits
GCC is a C compiler, the above code is not legal C. It is legal C++
however
GCC is the GNU Compiler Collection.
It currently contains compilers for C,C++,Fortran,Java and others.
So it’s not C.
(as far as I can tell) so it should compile with G++. To make it legal C
(to
The gcc frontend decides by file-endings how sources should be compiled.
the g++ frontend therefore is just to let the compiler interprete the
source as c++ code independently on the file-ending.
compile with GCC) move the SDL_Surface *screen; line to the top of the
main
function. C++ allows “inline variables” (not sure if this is the right
term), in C you must specify variables at the top of a function or at
the
global scope.
Dirk Gerrits
Zordan E.
Well I’m mostly a Windows user so sorry for my Linux ignorance.
But the line he used to compile was:
"gcc sdltest.c -o sdltest sdl-config --cflags --libs sdl"
and that clearly compiles in C not C++ right?
compile with GCC) move the SDL_Surface *screen; line to the top of the
main
function. C++ allows “inline variables” (not sure if this is the right
term), in C you must specify variables at the top of a function or at
the
global scope.
Also not true. In C variables must be declared at the beginning of the
local scope or
in global space. It has nothing to do with functions per se.
int main ()
{
int i = 0;
printf ("…");/* whatever/*
{
int j = 0;
}
}
thats also legal in C last time I checked.
Mainly correct, but since the C99 standard, declaring variables
in the middle of the code is now legal C.
Paulo Pinto (aka Moondevil in demoscene)
pjmlp_pt at yahoo.com – http://www.progtools.org
"If you think education is expensive, try ignorance" - Derek Bok
----- Original Message -----
From: leimbacd@bellsouth.net (David Leimbach)
To:
Sent: Wednesday, February 27, 2002 5:18 AM
Subject: Re: [SDL] Simple SDL Problem
Also not true. In C variables must be declared at the beginning of the
local scope or
in global space. It has nothing to do with functions per se.
int main ()
{
int i = 0;
printf ("…");/* whatever/*
{
int j = 0;
}
}
thats also legal in C last time I checked.
Mainly correct, but since the C99 standard, declaring variables
in the middle of the code is now legal C.
There are MANY new additions to C99. Variable length arrays are one of
them yet I don’t know any implementations of C99 to be “done”. Nor do I
believe anyone should start
writing all their C code in C99 standard conformant style since its less
likely to be portable. Other than that you are 100% correct.
I have gcc-3.0.4 on my FreeBSD box. Thanks for the link all the same!> —
Paulo Pinto (aka Moondevil in demoscene)
pjmlp_pt at yahoo.com – http://www.progtools.org
"If you think education is expensive, try ignorance" - Derek Bok