Hi!

I am trying to port some code from avr-gcc to SDCC to the mcs51
architecture.

Version:
d:\pjrc\nutbld\c>sdcc -v
SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08
2.7.0 #4818 (May 31 2007) (MINGW32)

The stripped-down code is:

// code starts on NEXT line ----------------------

char *strtok_r(char *s, char *delim, char **last)

{
    char *spanp;
    int c, sc;
    char *tok;

    tok = s - 1;

    /*
     * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
     * Note that delim must have one NUL; we stop if we see that, too.
     */
    for (;;) {
        c = *s++;
        spanp = (char *) delim;
        do {
            if ((sc = *spanp++) == c) {
                if (c == 0)
                    s = /*NULL*/ 0;
                else 
                        *s[-1] = 0;  // <- line 23 
                *last = s;
                return (tok);
            }
        } while (sc != 0);
    }
    /* NOTREACHED */
}
// code ends here  ------------

When compiling this code I receive:

d:\pjrc\nutbld\c>sdcc -c -mmcs51   --model-large  -DPJRC_87C52
-D__HARVARD_ARCH__ -I../.././nutbld/include  -I../.././nut/include
../.././nut/c/string/sigvtest.c -o string/sigvtest.o
../.././nut/c/string/sigvtest.c:23: error 27: Pointer required

Is this incorrect C code? After paging around in a C-textbook I found the
construct "*(s-1) = 0;" (Herbert Schild: teach yourself C, page 177) which I
tried. That one lead to:

d:\pjrc\nutbld\c>sdcc -c -mmcs51   --model-large  -DPJRC_87C52
-D__HARVARD_ARCH__ -I../.././nutbld/include  -I../.././nut/include
../.././nut/c/string/sigvtest.c -o string/sigvtest.o
../.././nut/c/string/sigvtest.c:23: warning 84: 'auto' variable '(null)' may
be
used before initialization
Caught signal 11: SIGSEGV

The SIGSEGV also occurs if I change the statement to " *s = 0;" (and I am
quite sure that is legal C ;-)


Interestingly, if I remove the "for (;;)" or the "do" statement and the
corresponding curly braces, the code compiles OK.

I also tried SDCC version 2008-01-25. All tests lead to the same result.

Am I doing something wrong here or did I run into a compiler problem?

Regards
Ernst


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to