delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/26/05:33:48

From: G DOT DegliEsposti AT ads DOT it
To: "Greg Bell" <gregbl AT ihug DOT co DOT nz>
cc: djgpp AT delorie DOT com
Message-ID: <C12565D3.00390BB7.00@vega.ads.it>
Date: Thu, 26 Mar 1998 11:31:27 +0100
Subject: Re: C Newbie - Pointers to Structures Problem
Mime-Version: 1.0




>void swap_points(POINTPTR a, POINTPTR b) //Assign pointer types to a & b
>{
>   POINTPTR temp; //Create a temporary address holder
>   temp->x = a->x; //Shift point a to temp
>   temp->y = a->y;
You can't do this: temp doesn't point to anything, or better it points to
some invalid area. While TC doesnt' complain about this, DJGPP detects an
access to invalid memory and stops the program.

Under TC you were lucky it didn't touch some important areas of memory,
leading to some not obvious malfunction.

If you do like this the space is allocated on the stack, and your program
shouldn't crash anymore: (at least in this place :-)

   POINT temp; //Create a temporary address holder
   temp.x = a->x; //Shift point a to temp
   temp.y = a->y;
   // and so on...
BTW. the ANSI standard for C requires main to return int and not void.

ciao
  Giacomo



- Raw text -


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