Question on syntax

Jim via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 8 22:28:31 PST 2016


Hi,

I'm a very experienced C++ programmer, looking at a program 
written in D. D is similar enough to C++ and Java that I have no 
problem understanding it - except for one thing. I think I may 
have figured it out, but I want to confirm my understanding.

What does it mean when a variable name starts with a '.'

Here's an extract from the code:
/// move.d ////////////
module move;

import empire;
import eplayer;
import sub2;

[...]

void updlst(loc_t loc,int type)		// update map value at loc
{
    int ty = .typ[.map[loc]];		// what's there

... etc.
(loc_t is an alias for int)

Would the equivalent in C or C++ be:

typedef int loc_t;
extern int typ[];
extern int map[];
void updlst( loc_t loc, int type )
{
    int ty = typ[map[loc]];

/////// var.d  ////////////////////////////////
module var;
import empire;
import eplayer;

int typ[MAPMAX] = ...etc...
ubyte map[MAPSIZE] = [0,];	// reference map

If you need more context, the complete source code is available 
from http://www.classicempire.com/


More information about the Digitalmars-d-learn mailing list