Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!goblin1!goblin.stu.neva.ru!postnews.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 28 Jul 2011 03:25:07 -0500 Message-ID: <4E311CE4.61AC@mindspring.com> Date: Thu, 28 Jul 2011 04:25:08 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: is there anything unstandard in the c part here 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> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 38 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.217.221 X-Trace: sv3-6QO+U9NgWr2iOGsSiR8P2cIwjdFUkrepK4jFNZcfNEsjiSVgli1AyrjAi5sOMjWEPJa5MzxScS4o0Sa!zRRlWy3CzUdEbZukD9HXpAc1+sMclSE+k38axlqOYROXoPaUhKEXAzxBhodKdkWAJhNSO7xWDxGw!uYuWpMl71VA= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2525 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:8799 Willem wrote: > > 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) ITYM #define NEW(x, n) ((x) = malloc((n) * sizeof *(x))) -- pete