Rudolf <rthered@bigfoot.com> writes:
[color=blue]
> In article <438eac39.145002778@news.xs4all.nl>,
>
rlb@hoekstra-uitgeverij.nl (Richard Bos) wrote:
>[color=green]
> > "yezi" <ye_line@hotmail.com> wrote:
> >[color=darkred]
> > > is some mem cat function with is like "strcat" ?[/color]
> >
> > No, and there cannot be. Consider: how does strcat() know where the
> > first string ends? How would a hypothetical memcat() do the same? (Hint:
> > it cannot.)[/color]
>
> Since functions like free() and realloc() know how big a memory region
> is, then why can't the hypothetical memcat() know how big it is?[/color]
What would be the semanics of the following program with your
suggested memcat?
#inlcude <stdlib.h>
#include <memcat_header.h> /* whatever that is */
#define BUF_SZ 100
int static_buffer[BUF_SZ];
int* static_ptr;
int main(void)
{
int automatic_buffer[BUF_SZ];
int* automatic_ptr;
int* free_store_ptr = malloc(BUF_SZ * sizeof *free_store_ptr);
/* check for malloc failure */
for (i = 0; i < sizeof static_buffer; ++i) {
static_buffer[i] = i;
automatic_buffer[i] = i;
free_store_ptr[i] = i;
}
static_ptr = static_buffer + BUF_SZ / 2;
automatic_ptr = automatic_buffer + BUF_SZ / 2;
/*
* In the following calls to memcat:
* how much memory would be copied,
* and where would the destiantion be?
* Explain that, and I'll tell you why
* memcat as your proposal can't exist
*/
memcat(static_ptr, automatic_buffer);
memcat(automatic_ptr, static_ptr);
memcat(free_store_ptr, automatic_ptr);
/* and so on, with every possible combination... */
return EXIT_FAILURE;
}
/Niklas Norrthon