Mail Archives: djgpp/2000/08/25/06:02:05
Radical NetSurfer <radsmail AT juno DOT com> 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.
- Raw text -