Page 1 of 1

problem with string.h ???

Posted: Sun Jun 12, 2005 10:43 am
by dlanor
Yesterday I compiled the latest ps2sdk, and discovered that with this some stuff now fails to compile that did so error-free before. One example is LaunchELF, which gave the following result at 'make all' from a clean state:

Code: Select all

ee-gcc -D_EE -O2 -G0 -Wall  -I/usr/local/ps2dev/ps2sdk/ee/include -I/usr/local/p
s2dev/ps2sdk/common/include -I. -I/usr/local/ps2dev/libito/include -I/usr/local/
ps2dev/sbv-1.0-lite/include -I/usr/local/ps2dev/libcdvd/ee -c main.c -o main.o
In file included from launchelf.h:11,
                 from main.c:1:
/usr/local/ps2dev/ps2sdk/ee/include/string.h:88: parse error before '\x0'
/usr/local/ps2dev/ps2sdk/ee/include/string.h:88: conflicting types for `memset2'

/usr/local/ps2dev/libito/include/itomisc.h:25: previous declaration of `memset2'

/usr/local/ps2dev/ps2sdk/ee/include/string.h: In function `memset2':
/usr/local/ps2dev/ps2sdk/ee/include/string.h:88: `p' undeclared (first use in th
is function)
/usr/local/ps2dev/ps2sdk/ee/include/string.h:88: (Each undeclared identifier is
reported only once
/usr/local/ps2dev/ps2sdk/ee/include/string.h:88: for each function it appears in
.)
/usr/local/ps2dev/ps2sdk/ee/include/string.h:88: `n' undeclared (first use in th
is function)
make: *** [main.o] Error 1
Of that mess only 3 lines are significant, so I'll repeat these here for clarity:

Code: Select all

/usr/local/ps2dev/ps2sdk/ee/include/string.h:88: parse error before '\x0'
/usr/local/ps2dev/ps2sdk/ee/include/string.h:88: conflicting types for `memset2'
/usr/local/ps2dev/libito/include/itomisc.h:25: previous declaration of `memset2'
Now, it is true that a 'memset2' function is declared at line 25 in itomisc.h, but that should not cause any conflict, since it is NOT true that either 'memset2' or the '\x0' sequence mentioned even exist in line 88 of string.h, which contains nothing of that kind. Instead, and unlike older versions of this file that I've seen, the current string.h has the following at line 88.

Code: Select all

static __inline__ void bzero(void * p, size_t n) { memset(p, 0, n); }
This should not cause any conflict with itomisc.h, as the name used is 'memset', not 'memset2' like the error message claims, and even that is a reference, not a declaration. So it seems to me as if the __inline__ implementation is somehow bugged, or possibly being bugged by some bad macro. I haven't found the real cause myself, but it could have something to do with other headers that were read before string.h, so here is a list of those, in referenced order:

ito.h (#includes all ito headers except itoglobal.h), stdio.h, tamtypes.h, sifcmd.h, kernel.h, sifrpc.h, loadfile.h, followed by string.h which gave the error.

As you can see, apart from the ito stuff (of libito 0.2.1), only ps2sdk files are involved, so the problem doesn't seem specific to the LaunchELF project. It could strike anyone using the same headers...

I hope someone else can solve this, because I can't get any grip on this myself.

NB: though I discovered this yesterday, the problem may have existed much longer, as I've been using ps2sdk 1.2 until yesterday.

Best regards: dlanor

Posted: Sun Jun 12, 2005 7:16 pm
by pixel
You most probably have a #define bcopy memset2 somewhere in libito. Bad, bad, baaaaad.

Posted: Mon Jun 13, 2005 12:27 am
by dlanor
pixel wrote:You most probably have a #define bcopy memset2 somewhere in libito. Bad, bad, baaaaad.
Thanks, but I assume you meant 'bzero' rather than 'bcopy', and there is such a macro in itomisc.h, which seems to be the culprit. I guess I was too tired to see it earlier...

Code: Select all

#ifndef bzero
#define bzero( _str, _n )            memset2( _str, '\0', _n )
#endif
This would alter the definition of bzero in string.h into a definition of another memset2 function, and since it used other parameter names most of the error messages are explained, except one. I still don't understand where the "parse error before '\x0'" came from, as the '\x0' part simply doesn't exist, neither in string.h nor in itomisc.h...!?!

However, that hardly matters since the problem goes away when I edit launchelf.h so that ito.h is not #included until after string.h .

Best regards: dlanor

Posted: Mon Jun 13, 2005 12:42 am
by pixel
Yeah, bzero, not bcopy. And the "\0" gets translated into "\x0" which is fundamentally the same thing. Now replace "bzero(x, y)" in string.h by "memset2(x, '\x0', y)", and you have the full error message explained.