Page 1 of 1

Error compiling against PSXLIB

Posted: October 21st, 2013, 8:28 am
by jman
Hello,

I'm having a weird compile error if I use Orion_'s wrapper (PSXLIB).

The following code (just a proof):

Code: Select all

#include "System.h"

int main(void)
{
	System_Init(MODE_PAL, VMODE_16BITS, 320, 240, GsNONINTER, 0);
	short sprt_x;
	return 0;
}
Produces this error:

Code: Select all

test.c: In function `main':
test.c:6: parse error before `short'
Removing the System_Init() or moving up sprt_x declaration apparently "fixes" the problem.
I tried digging a bit, compiling PSXLIB with -Wall flag (which I usually do): more errors like that came out.

What could be the problem? Orion_, I hope you're around :)

Thanks

Re: Error compiling against PSXLIB

Posted: October 21st, 2013, 11:51 pm
by Shendo
You should declare all variables before calling any functions.

Re: Error compiling against PSXLIB

Posted: October 22nd, 2013, 12:33 am
by jman
Shendo wrote:You should declare all variables before calling any functions.
Errm... what? :)

It looks to me a bit of an awkard piece of advice.

Re: Error compiling against PSXLIB

Posted: October 22nd, 2013, 6:07 am
by Yagotzirck
There's nothing "awkward" in what he said, C89 forces variables to be declared before instructions.
long story short:

Code: Select all

int main(void)
{
   short sprt_x;
   System_Init(MODE_PAL, VMODE_16BITS, 320, 240, GsNONINTER, 0);
   
   return 0;
}

Re: Error compiling against PSXLIB

Posted: October 22nd, 2013, 8:17 am
by jman
Yagotzirck wrote:There's nothing "awkward" in what he said, C89 forces variables to be declared before instructions.
Interesting. So ccpsx adheres to the C89 standard (at least in this respect). I dind't know that nor I've found any mention in the docs about a C89 compliancy (I've never met a compiler with that constraint - not that I'm that knowledgeable in C language nor compilers for that matter, I've always worked/crosscompiled with recent version of GCC).

But thanks for clarifying this!

Re: Error compiling against PSXLIB

Posted: October 23rd, 2013, 12:37 am
by Yagotzirck
gcc allows a lot of non-standard operations, unless a specific standard is specified(e.g. if you add the -std=c89 parameter, variables must be declared before instructions on gcc as well, among the other things)
I'm not completely sure if ccpsx fully adheres to c89 standard, but it's the most plausible option considering it's way too outdated to support c99(which is the C standard allowing declaration of variables after instructions, variable length arrays and other fancy stuff)
But thanks for clarifying this!
you're welcome :)