From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: memset behavior Date: 24 Aug 2000 08:34:14 GMT Organization: Aachen University of Technology (RWTH) Lines: 40 Message-ID: <8o2mm6$76i$1@nets3.rz.RWTH-Aachen.DE> References: NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 967106054 7378 137.226.32.75 (24 Aug 2000 08:34:14 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 24 Aug 2000 08:34:14 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Radical NetSurfer wrote: > I had a line of code like this: > char buffer[100]; > printf("%d %s\n", (char*)memset(buffer, '-', 64)); This printf line is very buggy. The compiler would have warned you about it, in (much recommended) "-O2 -Wall -W" mode. There are two things you say you want to print in the format string, but only one actual argument to print. Also note that it's completely random what your program will do, because you don't terminate the 'string' created by that memset() call with a '\0' byte. > PROBLEM #2: > There's no such thing as a memcat() routine... > why? Because a block of memory, as such, has no such thing as an 'end' you could concatenate another block of memory to. > (growing_pointer *)memcat(destination, source, n_bytes); Impossible, as stated. But you can do size_t memcat(void *dest, size_t dest_len, void *src, size_t src_len) { memmove(((unsigned char *)dest) + dest_len, src, src_len); return dest_len + src_len; } > such that "growing pointer" is simply something that provides > the buffer address of 'source', and its length. C pointers don't provide any 'size' information, other than the size of the element they point to. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.