Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Works in Linux but doesn't in WindowsXP

This thread is locked; no one can reply to it. rss feed Print
Works in Linux but doesn't in WindowsXP
Niunio
Member #1,975
March 2002
avatar

I've developed a small scripting interpretor to prove myself (it's very simple but may be useful). I've wrote it in ANSY-C in GNU/Linux and it runs the test scripts perfectly. The simplest script is a "Hello, world!" and the most complex is a "Guess the number" game. If there's an error in the script, the interpretor throws its state in a text file (stacks, variables, execution point, etc.).

The problem comes when I try to run it in WindowsXP. It compiles the interpretor without errors nor warnings (I'm using the "-Wall" flag) but it has a very strange behavior:

  • The "Hello, world!" script doesn't shows anything: no screen output

  • The "Guess the number" script runs(?) but allows only 9 iterations!

  • When there's an error in the script the interpretor doesn't create the stat file.

  • If I set the interpretor's stack size up to 1000 elements it doesn't run any script!

The interpretor is simple, but all internals and documentation are written in Spanish. I've tried to isolate the problem, but when I run the modules separately it seems to run perfectly, and I can't isolate the interpretor itself. I've attached the latest "stable but under development" version of the project, but remember: all the documentation and internals are written in Spanish. I'm using MinGW32 3.4.2 and MSys 1.0.11.

Anybody else wrote an ANSI/POSIX C program that runs in GNU/Linux but doesn't in Windows? Does anyone knows why? Does anyone knows how to fix it?

-----------------
Current projects: Allegro.pas | MinGRo

Evert
Member #794
November 2000
avatar

Could this have to do with line endings?
Be sure to open text files with "rt" and write them as "wt" in Windows, otherwise things will break.

Disclaimer: I haven't looked at your source, so this may not be related to your problem in any way.

Niunio
Member #1,975
March 2002
avatar

Evert said:

Be sure to open text files with "rt" and write them as "wt" in Windows, otherwise things will break.

I did it, using "rb", "at" and "wt" and all the scripts are in DOS format and still not working.

Another thing: I'm using "stderr" to show the error messages. May be Windows override "stderr" and then I can't see the error messages ???

[edit]I've changed all "stderr" by "stdout" and everything is the same... :(

-----------------
Current projects: Allegro.pas | MinGRo

umperio
Member #3,474
April 2003
avatar

Niunio
Member #1,975
March 2002
avatar

OMG! I've changed the "rb" by "rt" and it said there's an error loading the scripts that doesn't work! But I see the code is right, doesn't it? I've translated the comments to english:

1/* Open the script file. */
2 Archivo = fopen (Arg[1], "rt"); /* I've changed "rb" */
3 if (!Archivo) {
4 fprintf (stderr, "Can't open file \"%s\".\n", Arg[1]);
5 return FALSE;
6 }
7/* Calculate file size. */
8 if (fseek (Archivo, 0, SEEK_END) != 0) {
9 fclose (Archivo);
10 fprintf (stderr, "Can't load the file \"%s\".\n", Arg[1]);
11 return FALSE;
12 }
13 Tamanno = ftell (Archivo); rewind (Archivo);
14/* Allocate. */
15 Programa = (char*)malloc(sizeof (char) * Tamanno);
16 if (!Programa) {
17 fclose (Archivo);
18 fprintf (stderr, "RAM error \"%s\".\n",
19 Arg[1]);
20 return FALSE;
21 }
22/* Load the file. */
23 if (fread (Programa, Tamanno, 1, Archivo) != 1) {
24 fclose (Archivo); free (Programa);
25/***** THIS IS THE ERROR MESSAGE IT SHOWS ****/
26 fprintf (stderr, "Error loading file \"%s\".\n", Arg[1]);
27 return FALSE;
28 }
29 fclose (Archivo);

Curiously there's a script that is loaded and run perfectly ???

[edit]I think there's a problem with the way I calculate the size of the file... When I use "rb" it gets the correct size, when I use "rt" it doesn't.

-----------------
Current projects: Allegro.pas | MinGRo

ReyBrujo
Moderator
January 2001
avatar

Remember that the formats are different. Where did you create the script, linux or windows?

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Niunio
Member #1,975
March 2002
avatar

I did created them in Linux, but I want to make it cross platform. That's was I used "rb" to load the scripts. The interpretor just skip the '\n' and '\r' characters as spaces.

[edit]That's really strange: I've added this line
printf ("%s", ""); fflush (stdout);
just after the initialization and used the "-pg" option (inspired by Dev-C++) and all works perfectly! Why? :o

[edit2] Forget it: after reboot Windows the magic disappears... :'( I think my program overwrites the system kernel or something, because after run the executable compiled without the "-pg" flag, recompile it with the "-pg" flag, then I can run the "Guess the number" script. I'm sure it's a bug from GCC or Windows, but who knows? ::)

-----------------
Current projects: Allegro.pas | MinGRo

Go to: