TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Paul Edwards
from: andrew clarke
date: 1996-05-15 01:49:00
subject: indirection

13 May 96 00:52, Paul Edwards wrote to All:

 > int *x;
 > int y;

 > y = 3 * x;

 > y = * x;

 > y = *x;

 > Which ones do you reckon are legal?   I am wondering how mulitplication
 > and indirection are distinguished between.  Is the space significant?

The second and third are legal.  The first is illegal as it effectively evaluates to:

  y = 3 *x;

which is not a valid expression.  Any whitespace following the asterisk
dereferencing x is insignificant.

Two methods (that immediately come to mind) of performing a multiplication
on the dereferenced pointer are:

  y = 3 * (*x);  /* the brackets are probably not required, but they
                  * ease readability */

  y = *x * 3;    /* this is probably even better */

Regards
Andrew

--- Msgedsq/2 3.38
* Origin: Blizzard of Ozz, Melbourne, Australia (3:635/727.4{at}fidonet)
SEEN-BY: 50/99 620/243 623/630 632/349 635/503 544 727 728 711/401 409 410
SEEN-BY: 711/413 430 808 809 934 712/515 713/888 714/906 800/1
@PATH: 635/727 544 50/99 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.