Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!.POSTED!not-for-mail From: Willem Newsgroups: comp.lang.c Subject: Re: is there anything unstandard in the c part here Date: Thu, 28 Jul 2011 07:58:04 +0000 (UTC) Organization: Stack Usenet News Service Lines: 39 Message-ID: References: <996dhnFhnlU1@mid.individual.net> <6e8108d6-cf53-4d7c-940d-8a0dcad1315b@y24g2000yqb.googlegroups.com> <87mxg01br8.fsf@gmail.com> <0.2383e3bc931506eb036c.20110728021651BST.87hb67qk58.fsf@bsb.me.uk> NNTP-Posting-Host: toad.stack.nl Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: mud.stack.nl 1311839884 68858 2001:610:1108:5010::135 (28 Jul 2011 07:58:04 GMT) X-Complaints-To: abuse@stack.nl NNTP-Posting-Date: Thu, 28 Jul 2011 07:58:04 +0000 (UTC) User-Agent: slrn/0.9.9p1 (FreeBSD) Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:8798 Ike Naar wrote: ) To be fair, the preferred idiom also relies on duplication: in ) ) p = malloc(n * sizeof *p); ) ) the duplication is benign, but if the pointer expression ) becomes more complicated, as in ) ) *(*co_matrix)[pivot] = malloc(n * sizeof **(*co_matrix)[pivot]); ) ) the duplication becomes a bit of a nuisance. ) Because of the duplicated complexity, a silly mistake like ) ) *(*co_matrix)[pivot] = malloc(n * sizeof *(*co_matrix)[pivot]); ) ) may creep in, which is not caught by the compiler, and is easily ) overlooked during code inspection. ) ) Also, if the pointer expression has side effects: ) ) a[j++] = malloc(n * sizeof *a[j++]); ) ) although the preferred idiom works okay here (thanks to the fact that ) sizeof does not evaluate its operand), this may confuse the reader. Which is why god invented macros. #define NEW(x,n) ((x)=malloc((n) * sizeof(x))) (If I remember correctly) SaSW, Willem -- Disclaimer: I am in no way responsible for any of the statements made in the above text. For all I know I might be drugged or something.. No I'm not paranoid. You all think I'm paranoid, don't you ! #EOT