Mail Archives: djgpp/2001/04/18/12:02:45
On Wed, 18 Apr 2001, Waldemar Schultz wrote:
> more problems with MINGW port of gcc-2.95.2:
>
> strw.c:
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> int main(void)
> {
> char *bbb="ABCDefgh";
>
> strlwr(bbb);
> printf("%s\n",bbb);
> return EXIT_SUCCESS;
> }
>
> #66:W98>gcc -c strw.c -g -W -Wall
> #66:W98>gcc strw.o -o strw.exe -mwindows -mconsole
> #66:W98>strw.exe
> STRW verursachte einen Fehler durch eine ungültige Seite [error: invalid
> page]
This is a classic gotcha with GCC. The bug is in your program: you are
trying to change a read-only string.
GCC by default puts constant strings into read-only storage, so trying to
modify it triggers a protection violation. This will happen on any
platform; DJGPP avoids this problem because our .data and .text segments
overlap (due to subtleties of exception handling in DPMI environment),
and that prevents us from making the code segment write-protected. MinGW
doesn't have this problem, so your bug is exposed.
- Raw text -