Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: double free Date: Mon, 11 Jul 2016 10:44:41 -0700 Organization: None to speak of Lines: 39 Message-ID: References: <577ba42f.13700328@news.xs4all.nl> <48c43c3f-8e7e-0509-5b9d-04133e7bb537@verizon.net> <57837892.8808984@news.xs4all.nl> <481f30b4-acb3-4445-92b3-c403dc3e51f7@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="15834"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19oYVj26bNj+PAWJ9GCnhkM" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:hGa/PEbEgBBJw7XezD0ddvYDKmQ= sha1:k75SAXnQLYXe5pTgmr1K7m+ALLg= Xref: csiph.com comp.lang.c:90215 Malcolm McLean writes: > On Monday, July 11, 2016 at 12:01:28 PM UTC+1, Richard Bos wrote: >> David Brown wrote: >> >> > int* array = (int*) malloc(10 * sizeof(int)); >> > Comprehensible. malloc 10 times the size of an int. >> >> int *array = malloc(10 * sizeof *array); >> > Gibberish. > malloc ten times sizeof times array? Ten times the size of the array? > Code like that is a potential source of error and confusion. Gibberish. (I'm referring to what you just wrote, not to the code.) All that's necessary to understand that code is a reasonable knowledge of C and/or familiarity with that particular idiom. I presume *you* understand it, Malcolm, even if you don't like it. Are you assuming that other C programmers lack your understanding? Sure, someone who doesn't know that sizeof is an operator, and that * is both a binary operator (multiplication) and a unary operator (dereferencing) would have difficulty understanding that line. The cure is to learn. If you wanted to add parentheses to make it clearer: int *array = malloc(10 * sizeof (*array)); I wouldn't object strongly (though I wouldn't bother to do so myself). -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"