You should use a seq. You would not need size as its part of seq as .len.
    
    
    type
      Stack[T] = object
        top: int
        A: seq[T]
    
    
    Run

If you NOT going interface with C there is no point in using C style arrays.

BUT if you want to emulate C ... some thing you should not need to do often if 
ever you can do it this way:
    
    
    template `+`[T](p: ptr T, off: int): ptr T =
      cast[ptr type(p[])](cast[ByteAddress](p) +% off * sizeof(p[]))
    
    template `[]=`[T](p: ptr T, off: int, val: T) =
      (p + off)[] = val
    
    type
      Stack[T] = object
        top: int
        size: int
        A: ptr[T]
    
    var stack = Stack[uint16]()
    stack.top = 0
    stack.size = 2
    stack.A = cast[ptr uint16](alloc(sizeof(uint16) * stack.size))
    stack.A[0] = uint16 12
    stack.A[1] = uint16 12
    
    
    Run

Reply via email to