Pointer to Constant

2021-10-23 Thread morrissel311
Hi there! this was so informative. thank you so much for sharing.

Pointer to Constant

2021-10-21 Thread Araq
> Edit: Okay, not a bug, but returning a var Thingy introduces a copy, which is > not what I wanted. No, the copy is introduced here `var thing = getInner(ot)` as `var T` return values mirror what happens with array access, a named entity is observable and a copy, compare that to `var thing = s

Pointer to Constant

2021-10-21 Thread templatedperson
> [...] 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'

Pointer to Constant

2021-10-21 Thread Araq
While Nim has no support for const pointers directly, you could easily create a wrapper type that enforces no mutation to happen. But it's not required here and something like type Thingy = object x*: int OwnsThingy = object t: ptr Th

Pointer to Constant

2021-10-21 Thread templatedperson
Is there a way to return a pointer to constant in Nim? For example: type Thingy = object x*: int OwnsThingy = object t: ptr Thingy proc makeOwnsThingy(): OwnsThingy = result.tt = cast[ptr Thingy](alloc