delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/11/10:45:28

From: "Cephaler" <cephaler AT hotmail DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: pointers and errors make cephaler go crazy
Date: 11 Aug 1998 14:38:15 GMT
Organization: ICGNetcom
Lines: 57
Message-ID: <01bdc535$858a16c0$0100007f@scully>
NNTP-Posting-Host: wbg-va2-20.ix.netcom.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

  Ok, that sigill thing that plagued my code is gone now, because I just
spent 40-50 hours rewriting my code. The problem was with pointers, so I
fixed up some hacks (all hacks are gone, clean code now) and initialized
each and every pointer and made sure I freed them... So I compile and it
still doesn't work, not it's a sigsegv, and rhide is pointing at a
perfectly legitimate line of code..

blit(tiles[map[x][y]->tile],screen,0,0,x*32,y*32,32,32)

so I changed it

blit(tiles[&map[x][y]->tile],screen,0,0,x*32,y*32,32,32)

that killed the error but then gave me bad values (>1000000 memory
address?) so I tried putting that stupid '&' in every place imaginable, no
luck... So i tried playing around with the '*' thing, no luck... I'm not
the greatest at using pointers, but I know a few things: & returns address,
* returns value, -> is used for things in structures that are pointers, .
is used for 'normal' structures... I guess that example up there isn't too
clear A few bits of code..

typedef struct {
  unsigned char tile,tag;
} _tile;

_tile *map[100][100];

....

for(a=0;a<100;a++) {
  for(b=0;b<100;b++) {
    if((map[a][b]=(_tile *)malloc(sizeof(_tile)))==NULL) {blah}
  }
}

....
int fhandle
fhandle = open("foobar",O_RDONLY|O_BINARY,S_IWUSR) 
read(fhandle,map,sizeof(map));
....

now, question #1: how would I go about blitting a tile <x> that is in an
array of tiles, where <x> is specified by <tile> in <map>, which is a 2d
array of _tile type pointers?

#2: Am I initializing map right...? that seems too hack-ish for me

Thx for help on sigill problem btw, helped me realize what was wrong

- Cephaler -

p.s. subject is simpsons quote (no tv and no beer make homer go crazy..
halloween episode)


      

- Raw text -


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