Mail Archives: djgpp/1996/05/20/09:57:37
Here is an interesting 'bug' that I have found in cwsdpmi. When I compile
the attached file and run it under dos, it blows up giving me a SIGSEGV, but
it works correctly under a windows dos box and in linux dosemu. Here
is the program:
#include <stdio.h>
typedef struct {
int x;
int y;
} foo;
foo *bar;
void main()
{
bar->x = 3;
bar->y = 4;
printf("x = %d\n", bar->x);
}
As you can see, there isn't much to this program, and I have compiled
programs that are a lot more complex than this with the exact same
system setup with no problems.
You have never declared any variable, nor allocated any space, to which bar can
point. Bar is only a pointer and uninitialized it is probably garbage in a
Windos DOS box and under dosemu but properly NULL under CWSDPMI. Make it:
#include <stdio.h>
typedef struct {
int x;
int y;
} foo;
foo fred;
foo *bar = &fred;
void main()
{
bar->x = 3;
bar->y = 4;
printf("x = %d\n", bar->x);
}
and all will be hunky dory.
--
Art S. Kagel, kagel AT quasar DOT bloomberg DOT com
A proverb is no proverb to you 'till life has illustrated it. -- John Keats
- Raw text -