From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2619 Path: news.gmane.org!not-for-mail From: Igmar Palsenberg Newsgroups: gmane.linux.lib.musl.general Subject: Re: malloc(0) behaviour Date: Tue, 15 Jan 2013 23:28:14 +0100 Message-ID: References: <20130114180533.GP20323@brightrain.aerifal.cx> <20130115110618.GA4468@port70.net> <4FA1FD0D-5C34-4DE0-AF27-1F48BB194005@palsenberg.com> <20130115134802.GY20323@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1358288911 9805 80.91.229.3 (15 Jan 2013 22:28:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 15 Jan 2013 22:28:31 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2620-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jan 15 23:28:49 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1TvEzr-0004lK-ST for gllmg-musl@plane.gmane.org; Tue, 15 Jan 2013 23:28:44 +0100 Original-Received: (qmail 21704 invoked by uid 550); 15 Jan 2013 22:28:27 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 21696 invoked from network); 15 Jan 2013 22:28:26 -0000 In-Reply-To: <20130115134802.GY20323@brightrain.aerifal.cx> X-Mailer: Apple Mail (2.1499) Xref: news.gmane.org gmane.linux.lib.musl.general:2619 Archived-At: >>=20 >> That's there to access if size is 0 ? Sure, you can access : >>=20 >> struct foo { >> }; >=20 > This is a constraint violation. C does not allow empty structs, and > even if it did, they would not have size 0, since no type or object > ever has size 0 in C. GCC thinks otherwise :=20 #include #include struct test { }; int main(int argc, char **argv) { char *x =3D NULL; printf("sizeof test : %d\n", sizeof(struct test)); return 0; } [igmar@devel ~]$ ./x sizeof test : 0 It gives me a warning, but doesn't error out. Olders version might = behave differently, I don't have those installed. The LLVM compiler does = the same. No idea what the standard says, but your remarks sounds correct to me.=20= >>=20 >> which is size 0. I do wonder what that gives me in practice. That is, = not counting the fact that : >>=20 >> if (size =3D=3D 0) >> size =3D 1; >>=20 >> was a common practice in malloc() implementations a while ago. >=20 > Of course, this is the canonical, simplest way to make malloc(0) > return a unique pointer. Enough for this thread. I did got the answer I wanted, and the result I = want is easy to realise. Not mu intention to irritate people. Igmar