www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/28/19:19:06

Message-ID: <351D93C1.60A91521@mail.ucsm.edu.pe>
Date: Sat, 28 Mar 1998 19:20:19 -0500
From: rpinnell AT characato DOT ucsm DOT edu DOT pe
Reply-To: rpinnell AT characato DOT ucsm DOT edu DOT pe
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: PROBLEM WITH ARRAY IN STRUCT

Hi I am trying to write a program using DJGPP and the Allegro graphics
library.  I am having a problem with an array inside a struct.  Here is
example of the type of thing I am doing.

#include <stdio.h>
#include <stdlib.h>
#include <allegro.h>
#include <string.h>
#include "my.h"

struct my
{
char block[336];
}*pt;

/* START OF MAIN */
int main()
{
int i=0;
DATAFILE *df;
char *buf;

   /* INITIALISE ALLEGRO */
   allegro_init();
   install_keyboard();

    /* LOAD DATAFILE */
   strcpy(get_filename(buf), "my.dat");
   df = load_datafile(buf);

   /* SET GRAFICS MODE */
   set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0);
   set_palette(df[mypal].dat);

   /*   FILL  BLOCK WITH ZEROS  */
   while(i<336)                  /* THIS SEEMS TO CAUSE LOTS OF PROBS */

      pt->block[i++]=0;         /* WHY? WHY? WHY?                    */

readkey();
return 0;
}

The above code does nothing of course it is just to demonstrate, it
compiles ok.  The program I am writting is much more complex and
contains multiple files.  The problem is the line which writes data to
the array in the struct my..  In my program I am passing a  pointer to
this struct to various functions and manipulating the data within the
array. However whenever I try and initialise the array in the struct
with 0´s, as in the above examples I get all sorts of problems. The
problems don´t seem to be consistent, sometimes it works ok when I
compile other times it compiles ok but I get exiting due to signal
SIGSERV.  I tried running the program through the  rhide debugger and
again the errores seem to be inconsistent, somtimes the error is when
the program  loads in the allegro datafile sometimes elsewhere.  There
is no problem before I add the loop to initialise the array in the
struct however.  I´m sure I am doing something very very silly here can
someone please tell me what it is.
Richard Pinnell
Arequipa Peru



- Raw text -


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