www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/20/09:57:37

From: kagel AT quasar DOT bloomberg DOT com
Date: Mon, 20 May 1996 09:46:11 -0400
Message-Id: <9605201346.AA01494@quasar.bloomberg.com >
To: snarfy AT goodnet DOT com
Cc: djgpp AT delorie DOT com
In-Reply-To: <4nlke7$aka@news1.goodnet.com> (snarfy@goodnet.com)
Subject: Re: bugs in cwsdpmi?
Reply-To: kagel AT dg1 DOT bloomberg DOT com

    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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019