I'm trying to do something like this:
    
    
    type
      ThreadID* = distinct uint8
      
      Msg*[T] = object
        sender*: ThreadID
        receiver*: ThreadID
        previous: pointer#ptr[Msg[any]]
        content*: T
    
    let space = alloc0(sizeof(Msg[int]))
    let m = cast[ptr[Msg[int]]](space)
    #let p:ptr[Msg[any]] = m.previous
    

I would like to define "previous" as something meaning ptr[Msg[any]], so that a 
ptr to any concrete Msg[?] can be assigned to it. I'm sure this has been asked 
before, but no mater how I phrase it, nothing came up in the search.

The "ugly workaround" is to cast the pointer to some concrete version of Msg, 
for example Msg[int], and access the "non generic fields", but not content. 
OTOH, I'm not even sure if this is safe, or if the compiler could possibly 
choose a different "byte offset" for the "non generic fields", based on T.

Reply via email to