Thread overview | |||||
---|---|---|---|---|---|
|
November 09, 2016 Question on syntax | ||||
---|---|---|---|---|
| ||||
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/ |
November 09, 2016 Re: Question on syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jim | 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);
}
|
Copyright © 1999-2021 by the D Language Foundation