> [...] there are few reasons to directly go for `ptr` and `alloc` in Nim, Nim 
> is not D.

Agreed, though I'm assuming I have to use `ptr` for C types.

By the way, is following code contain a bug? I was trying to see if `: var 
Thingy` return type returns a reference (or a pointer) but it doesn't seem to 
do that:
    
    
    type
        Thingy = object
            x*: int
        
        OwnsThingy = object
            t*: ptr Thingy
    
    
    proc makeOwnsThingy(): OwnsThingy =
        result.t = cast[ptr Thingy](alloc(Thingy.sizeof))
        result.t.x = 100
    
    proc getInner(self: OwnsThingy): var Thingy = self.t[]
    
    proc inc(self: var Thingy) = self.x += 1
    
    when isMainModule:
        let ot    = makeOwnsThingy()
        var thing = getInner(ot)
        
        echo ot.t[] # Prints 100
        thing.inc()
        echo ot.t[] # Prints 100 again, should have printed 101, right?
    
    
    Run

Reply via email to