Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!74.125.46.80.MISMATCH!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: Wed, 11 May 2011 07:10:31 -0500 Message-ID: <4DCA7CBA.5F7A@mindspring.com> Date: Wed, 11 May 2011 08:10:34 -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: Passing an integer to a function that accepts a void pointer References: <80905e4d-6b11-4843-b4e7-96f0c7db8b23@l18g2000yql.googlegroups.com> <4b5e6c3e-0266-44e4-8f29-dd46a91eeb40@x6g2000yqj.googlegroups.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 39 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.154.223.42 X-Trace: sv3-3OEr0Zp6uEo4UcIT9TtnKLKpLDgJWDx7ceK3Et8WrER18usMnSzC3hOz0iVlkmwyWXhmwB1GNjb1Lnh!Zi+MQ4VAS1qgOmzn3I5RXt4aCYBSOeQSTzI2HonfQcm7VRWJSGRnzsfw5cVWg4wCi/rqYTjwPXeR!F2Vfu5DTyw== 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: 2033 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:3745 Tom St Denis wrote: > > On May 11, 6:01 am, pozz wrote: > > What do you think about this code? > > > > int foo(const void *Args) { > > printf("%d\n", (const int)Args); > > return 0; > > > > } > > > > int main(int argc, char *argv[]) { > > foo((void *)10); > > return 0; > > > > } > > > > It seems work and it should be nice if it is a sufficient portable way > > to pass integers as pointers. > > > > Why don't I declare foo() to directly accept int? Because it is a > > callback of a library I can't change and the prototype of the callback > > is well defined by the library to accept void pointer. > > Why not just do this > > int bar = 10; > foo(&bar); > > And inside foo do > > printf("%d\n", *((int *)Args)); > > That way the program is actually portable. That's what I was thinking too. -- pete