Question on syntax

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Nov 8 22:46:03 PST 2016


On 09/11/2016 7:28 PM, Jim wrote:
> 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/

This is a set of syntax that isn't ugh used often (I'm pretty sure I 
know what it is). It just isn't needed.

Empire's code was ported to D during the early days of D1, its 
documentation doesn't come close to best practices let alone the code 
itself.

Example:

int x;

void main() {
	x = 8;

	import std.stdio;
	writeln(.x);	
}


More information about the Digitalmars-d-learn mailing list