delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/17/10:12:35

From: ams AT ludd DOT luth DOT se (Martin Str|mberg)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: What's wrong with this code snippet ?
Date: 17 Oct 1999 12:15:36 GMT
Organization: University of Lulea, Sweden
Lines: 38
Message-ID: <7ucel8$b1t$1@news.luth.se>
References: <c6wJONRNMABaX1eVyyz+aTSlhqUz AT 4ax DOT com>
NNTP-Posting-Host: queeg.ludd.luth.se
X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Kevin (krugman AT nospam DOT demon DOT co DOT uk) wrote:
: Hi all.
: 
: yet another dumb question, but I can't seem to spot 
: where I'm going wrong.
: 
: 
: 
: const int NUM_TILES = 320;  // This is global
: 
: int kill_list[NUM_TILES];   // This isn't
: 
: empty_kill_list(kill_list);
: 
: // Set each element of the kill list to 999
: void empty_kill_list(int *list)
: {
:   memset(list, 999, sizeof(int) * NUM_TILES);
: }
: 
: this doesn't set any of the kill list elements to 999,
: when I look at them, they appear to have been set to
: some unfeasably large negative number.
: 
: using a for loop to set the elements works fine, but is 
: probably much slower.
: 
: Any ideas ?

Yes. The second argument to memset is supposed to be in the range
0-255 (or -128 - 127). You are setting each int to "( (999 % 256) <<
24 ) + ( (999 % 256) << 16 ) + ( (999 % 256) << 8 ) + (999 % 256)"
(untested pseudo-code).


Pärt, Litany,

							MartinS

- Raw text -


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