Deutsch   English   Français   Italiano  
<6255bb4153bcc571db879cf847ee3a110080c4fc.camel@gmail.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: wij <wyniijj5@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: What is your opinion about init_malloc?
Date: Fri, 14 Mar 2025 23:56:30 +0800
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <6255bb4153bcc571db879cf847ee3a110080c4fc.camel@gmail.com>
References: <vr1e67$1fa1p$1@dont-email.me>
	 <vr1j5o$1jg76$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Fri, 14 Mar 2025 16:56:31 +0100 (CET)
Injection-Info: dont-email.me; posting-host="a499a0831bd7f6466cd8a05ed4720a40";
	logging-data="1693018"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+l4m32/QXL77a6wBTzAi1E"
User-Agent: Evolution 3.54.3 (3.54.3-1.fc41)
Cancel-Lock: sha1:uWemfBXDCQwKZ2M2zvC/tKrCjFE=
In-Reply-To: <vr1j5o$1jg76$1@raubtier-asyl.eternal-september.org>
Bytes: 2437

On Fri, 2025-03-14 at 16:49 +0100, Bonita Montero wrote:
> Am 14.03.2025 um 15:24 schrieb Thiago Adams:
> > What is your opinion about init_malloc?
> > One problem it solves it to initialise a const objects on heap.
> >=20
> > #include <stdlib.h>
> > #include <string.h>
> > #include <stdio.h>
> >=20
> > void * init_malloc(size_t size, void * src)
> > {
> > =C2=A0=C2=A0 void * p =3D malloc(size);
> > =C2=A0=C2=A0 if (p) {
> > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 memcpy(p, src, size );
> > =C2=A0=C2=A0 }
> > =C2=A0=C2=A0 return p;
> > }
> >=20
> > #define ALLOC(OBJ) ((typeof(OBJ)*) init_malloc(sizeof(OBJ), &(OBJ)))
> >=20
> > ////////// SAMPLE=C2=A0 //////////
> >=20
> > struct Mail {
> > =C2=A0=C2=A0=C2=A0=C2=A0 const int id;
> > };
> >=20
> > int main () {
> > =C2=A0=C2=A0=C2=A0=C2=A0 struct Mail* p0 =3D ALLOC((struct Mail){.id=3D=
 1});
> >=20
> > =C2=A0=C2=A0=C2=A0=C2=A0 struct Mail* p1 =3D init_malloc(sizeof *p1, &(=
struct Mail){.id=3D 1});
> >=20
> > =C2=A0=C2=A0=C2=A0=C2=A0 auto=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0 p2 =3D ALLOC((struct Mail){.id=3D 1});
> >=20
> > }
> >=20
> > (I also posted on reddit)
> >=20
>=20
> C still seems to be a ridiculous language.
>=20

If it tries to exceed 'High level assembly', it could be ridiculous.
Same as C++, if it tries to be 'not-C'.