digitalmars.D.learn - Question on syntax
- Jim (33/33) Nov 08 2016 Hi,
- rikki cattermole (13/46) Nov 08 2016 This is a set of syntax that isn't ugh used often (I'm pretty sure I
- ketmar (2/3) Nov 08 2016 `.a` --> `::a`.
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/
Nov 08 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);
}
Nov 08 2016
On Wednesday, 9 November 2016 at 06:28:31 UTC, Jim wrote:What does it mean when a variable name starts with a '.'`.a` --> `::a`.
Nov 08 2016









rikki cattermole <rikki cattermole.co.nz> 