cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/17/11:43:11

From: eplmst AT lu DOT erisoft DOT se (Martin Stromberg)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: What's wrong with this code snippet ?
Date: 17 Oct 1999 13:51:36 GMT
Organization: Ericsson Erisoft AB, Sweden
Lines: 31
Message-ID: <7uck98$sp4$2@antares.lu.erisoft.se>
References: <c6wJONRNMABaX1eVyyz+aTSlhqUz AT 4ax DOT com> <3809C8BE DOT 82C8A5F2 AT club-internet DOT fr>
NNTP-Posting-Host: propus-144.lu.erisoft.se
X-Newsreader: TIN [version 1.2 PL2]
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

flobere AT club-internet DOT fr wrote:
: > // Set each element of the kill list to 999
: > void empty_kill_list(int *list)
: > {
: >   memset(list, 999, sizeof(int) * NUM_TILES);
: > }

: Hi,

: Very simple...
: the memset function prototype is :
: memset(void *ptr, char c, unsigned long size)
: The second arg is a CHAR. It means is in 8bits,
: it also means you cannot go over 255 using memset.
: That is why you cannot set your array to 999.
: Memset is only useful when you need to initialize an
: array to 0.
: It is not much more slower to use a for loop. The
: compiler will surely optimize it to a rep sto instructions.

Well, it's not _that_ simple. First I suggest you look at the
prototype or documentation for memset() (hint-hint-nudge-
youknowwhatImean-wink) before assuming anything.

But you are right that memset is used to set chars not ints (at least
in DJGPP and Linux).


Right,

							MartinS

- Raw text -


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