ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/19/04:10:42

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Q: Typedef riddle
Date: Mon, 18 Nov 1996 18:43:35 -0800
Organization: Three pounds of chaos and a pinch of salt
Lines: 32
Message-ID: <32911ED7.49C9@cs.com>
References: <Pine DOT LNX DOT 3 DOT 91 DOT 961118182603 DOT 3316D-100000 AT hostr DOT bielbit DOT bielsko DOT pl>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp108.cs.com
Mime-Version: 1.0
To: bartosz AT hostr DOT bielbit DOT bielsko DOT pl
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

bartosz AT hostr DOT bielbit DOT bielsko DOT pl wrote:
> 
> > void Dump(thing *V)
> > {
> > printf("\n%i %i %i\n",*V[0],*V[1],*V[2]);
> 
>                         ^ ??????
> 
> Why are you using * operator. To get value of the 0 element you jaust
> need V[0]. If you use *V[0] you traet V[0] as a pointer.

That's NOT correct.  In that code, what is being passed to the function
Dump() isn't the array V, but a pointer to the array V.  So, to access
the array itself you need an extra dereference.  The problem with
Elliot's code was that it confused the precedence of the dereference
operator vs. the array operator.

Remember that 'thing' is a typedef that itself represents an array of
integers, so passing a reference to a 'thing' requires double
dereference to access the array itself.  To see this, take the code and
replace all references to 'thing' with the actual typedef, and you'll
understand.

-- 
John M. Aldrich, aka Fighteer I <fighteer AT cs DOT com>

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d- s+:- a-->? c++>$ U@>++$ p>+ L>++ E>+ W++ N++ o+ K? w(---) O-
M-- V? PS+ PE Y+ PGP- t+(-) 5- X- R+ tv+() b+++ DI++ D++ G e(*)>++++
h!() !r !y+()
------END GEEK CODE BLOCK------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019