Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: sizeof object got by dereferencing uniniitalized pointer Date: Thu, 28 Nov 2019 16:37:46 -0800 Organization: A noiseless patient Spider Lines: 19 Message-ID: <86eexr8qlh.fsf@linuxsc.com> References: <21e377ab-2a49-4f7e-bc18-72f1cee63204@googlegroups.com> <9d5ee6d4-607b-405f-83d9-afbe2b073cac@googlegroups.com> <76a74489-4a1f-4561-a01b-b2962a10bae4@googlegroups.com> <2119c5dc-fc01-4a74-93f4-8027c7cc210e@googlegroups.com> <43093894-ed52-47de-85f4-eadd92a1499e@googlegroups.com> <877e3j52do.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="81b92e3fa8397acac1ab5cf195ff75cd"; logging-data="26130"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18zoO3VIWZvfXqBglXaXrogWkYjpZOClno=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:Ij6ycQqdB/xrdihNekvPvvZIoaw= sha1:Mf5w3Hc5VJzb4t+y6SzWohu3KUI= Xref: csiph.com comp.lang.c:148206 Ben Bacarisse writes: > Thiago Adams writes: > > >> Only when applied to variably types, sizeof is in runtime. >> >> int n = 10; >> >> int(*buf)[n] = malloc(sizeof(int) * n); > > Why would you not write > > int (*buf)[n] = malloc(sizof *buf); > > ? Perhaps because, technically speaking, the right-hand side here has undefined behavior?