@dawkot To put it simply, what Araq says is: in the first case, the macro
operates directly on procA at compile time so it behaves as expected but in the
second case, it actually operates on p argument (which has no implementation as
it's not an actual procedure, therefore its implementation is
@Jehan The fact that an arbitrary string is ambiguous without a context is
probably the reason a context is passed as a separate parameter in Rust macros,
I guess. I sometimes miss that possibility in Nim, it would makes tricks
unnecessary and macros would be less of magic, I guess.
Mmh there is an error proc in macros that I _think_ does that:
[https://nim-lang.org/docs/macros.html#error,string,NimNode](https://nim-lang.org/docs/macros.html#error,string,NimNode)
@Araq Here is a minimal example. This is compiled with "vcc". It compiles to C,
but not to C++.
type
VolatilePtr*[T] = distinct ptr T
proc toVolatilePtr*[T](t: var T): VolatilePtr[T] =
cast[VolatilePtr[T]](addr t)
# Pretend we're actually checking it's
@stisa Actually, I meant "when sizeof(T) == 1" rather than "if sizeof(T) == 1"
(now corrected). But the problem is, that in the real code I want to support
multiple paramter sizes, and get a compile time error if the size is
unexpected. The example you gave me compiles, but fails at runtime.
I have the solution. It was a silly mistake. I had placed libui library at the
wrong place. Thanks for the response.
You can use asserts:
let b: byte = 42'u8
let c = 42'u16
proc test*[T](t: T): bool =
assert(sizeof(T) == 1, "invalid parameter size: " & $sizeof(T))
result = true
echo test(b)
echo test(c)
I'm trying to debug a compilation problem: the generic parameter of a proc
doesn't seem to match my expectation, so I'd like to write something like this:
let b: byte = 42'u8
proc test*[T](t: T): bool =
if sizeof(T) == 1:
result = true # ...
else:
@mratsim Would you mind if I make a reference to your lib in my bachelor thesis
about optimization?
To which folder did u copy the libui.h file? I have cloned the libui from git
completely into my repository and it exists in the UI folder.
10 matches
Mail list logo