about pointer syntax

spir denis.spir at gmail.com
Thu Oct 14 13:28:43 PDT 2010


As a way to start learning D by practicing, I'm trying to implement a symbol table as linked list: see prototype code of the structs below. (Hints about good D coding welcome :-)

2 little questions about pointers:
1. To please the compiler, I had to wrap dereferencing in parens, like in "(*symbol).name". Is this just normal (for disambiguation)?
2. Just noticed the compiler accepts "symbol.name", while symbol is a pointer: is there implicit dereferencing of pointers to structs? If yes, does this also apply to pointers to arrays (for information, this what Oberon does).

And a note: had forgotten to add an empty main(), just for compiling: the linker produced a rather big amount of error text without any hint to the actual issue. Maybe dmd could cope with that before calling gcc?

Finally: the reference is rather harsh for me, esp there are very few example (I have few practice of C, and none of C++); the bits of tutorials I found are too light or just started (toc points to empty pages). Is there anywhere online a kind of D programming guide, even not polished or possibly unfinished (I know about the book; maybe I'll order it, but in meantime...).

Thank you,

================== code ======================
struct Symbol {
    string name  = "" ;
    int element  = 0 ;
    Symbol* next = null ;
struct List {
    Symbol* first = null ;
    int element(string name) {
        Symbol* symbol = this.first ;
        while (symbol) {
            if ((*symbol).name ==  name) {return (*symbol).element ;} ;
            symbol = (*symbol).next ;
        return 0 ;

-- -- -- -- -- -- --
vit esse estrany ☣


More information about the Digitalmars-d-learn mailing list