On 14/03/2025 16:31, wij wrote:
On Fri, 2025-03-14 at 17:13 +0100, Bonita Montero wrote:
Am 14.03.2025 um 16:56 schrieb wij:
If it tries to exceed 'High level assembly', it could be ridiculous.
Same as C++, if it tries to be 'not-C'.
Thiago wants to mimic construction with new,
I've been wondering how C would mimic ctor/dtor for long long time,...
void * init_malloc(size_t size, void * src) looked reasonable, and
may be necessary in 'my assembly model'.
Why not pass it a constructor function as well? Something like:
void * init_malloc(void *src,
size_t size,
int(*ctor)(void *, const void *))
{
void *p = malloc(size);
if(p)
{
if(ctor != NULL)
{
if((*ctor)(p, src) == CTOR_FAIL)
{
free(p);
p = NULL;
}
}
else
{
memcpy(p, src, size);
}
}
return p;
}
This way, you can do a "deep copy" instead of a naive bit blit,
and one init_malloc fits all because you just write a new
constructor for each type that needs one and pass a NULL
constructor when a bit blit suffices.
--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)