The argument when not stated, is using let , in other word it's like put the 
variable in stack, that's why it has no address. To bypass that, you must pass 
the var to the argument so it's using the same memory place in heap.
    
    
    import endians
    import strutils
    
    proc parse[T](buffer: var openArray[uint8]): T =
      let pointer = addr(buffer[0])
      when sizeof(T) == 2:
        littleEndian16(addr(result), pointer)
      elif sizeof(T) == 4:
        littleEndian32(addr(result), pointer)
      else:
        result = (T)42
    
    var buffer = [0x01'u8, 0x23, 0x45, 0x67]
    
    echo toHex(parse[uint16](buffer))
    echo toHex(parse[uint32](buffer))
    

Reply via email to