* [const is a 
contract](https://quuxplusone.github.io/blog/2019/01/03/const-is-a-contract/).



I like to see that Nim could generate something similar to `f(O *a, const O 
*b)` for below f:
    
    
    type
      O {.byref.} = object ...
    
    proc f*(a: var O; b: O): int = ...
    
    
    Run

  * const is not only a contract, seriously



We need a const/immutable `ptr T` to help us from crash, not just reading and 
remembering the signature of the C function:
    
    
    {.emit: """
    const int a = 1234;
    const int *fconst(void) { return &a; }
    """
    .}
    
    proc myf(): ptr int {.importc: "fconst" nodecl.}
    
    proc f(): int =
      let p = myf()
      p[] = 456
      return p[]
    
    
    Run

P.S. C can't do **X** is not reason for Nim not to do **Y**.

Reply via email to