Error compiling against PSXLIB

All other SDK help, questions and information
Post Reply
jman
Rookie Programmer
Rookie Programmer
Posts: 110
Joined: Aug 13, 2013

Error compiling against PSXLIB

Post by jman » October 21st, 2013, 8:28 am

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

User avatar
Shendo
Verified
C Programming Expert
C Programming Expert
Posts: 250
Joined: Mar 21, 2012
I am a: Programmer
Motto: Never settle
PlayStation Model: SCPH-7502
Discord: ShendoXT
Location: Croatia, EU

Post by Shendo » October 21st, 2013, 11:51 pm

You should declare all variables before calling any functions.
Dev console: SCPH-7502, FreePSXBoot, CH340 serial cable.

jman
Rookie Programmer
Rookie Programmer
Posts: 110
Joined: Aug 13, 2013

Post by jman » October 22nd, 2013, 12:33 am

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.

Yagotzirck
Verified
Extreme PSXDEV User
Extreme PSXDEV User
Posts: 131
Joined: Jul 17, 2013

Post by Yagotzirck » October 22nd, 2013, 6:07 am

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;
}

jman
Rookie Programmer
Rookie Programmer
Posts: 110
Joined: Aug 13, 2013

Post by jman » October 22nd, 2013, 8:17 am

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!

Yagotzirck
Verified
Extreme PSXDEV User
Extreme PSXDEV User
Posts: 131
Joined: Jul 17, 2013

Post by Yagotzirck » October 23rd, 2013, 12:37 am

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 :)

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests