I have stumbled this error: "nim c main" gives "SIGSEGV: Illegal storage
access. (Attempt to read from nil?)" on machine setup: Nim Compiler Version
0.18.0 [Windows: amd64], "uname -a" -> MINGW64_NT-10.0 <name> 2.9.0(0.318/5/3)
2017-09-13 23:16 x86_64 Msys
Simple sources are as:
# lib1.nim
proc PresentModeA*[T:string|seq[byte]](d: T) =
echo "A Presenting: ", $d[0]
#lib2.nim
proc PresentModeB*[T:string|seq[byte]](d: T) =
echo "B Presenting: ", $d[0]
#main app
import
os, sequtils, strutils,
lib1, lib2
type
modes = enum
typeA, tyepB
var
mode = typeA
template PresentGeneric(s: typed) =
var dispatcher = @[PresentModeA, PresentModeB]
dispatcher[mode.ord](s)
proc main() =
# 'mode' is really dependant on optargs
let data = @[0x00.byte, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07]
PresentGeneric(data)
let text = "Something to shout about."
PresentGeneric(text)
main()
Is this design supported or should avoid generics pointers?
Thank you.