Details
Description
Usage:
unsafe [<ptrName> as <ptrType> = <data>]+:
<body>
unsafe blocks are only allowed when "-unsafe" flag as been passed to the compiler (CompilerParameters.Unsafe == true), otherwise an error is reported.
It declares pointer(s) to one or more value type references (<data>).
In the context of an unsafe block, an explode operator on a declared pointer is replaced with the indirection operator.
sizeof built-in meta-method is introduced, it accepts both type references (as in C#) and also variable references.
Example:
src = array[of byte](8) src[3] = 1 dst = array[of byte](8) dst[6] = 1 #replace an uint at a time from src to dst only if src is not zero unsafe psrc as uint = src, pdst as uint = dst: for i in range(len(src) / sizeof(psrc)): *pdst = *psrc unless *psrc == 0 psrc++ pdst++ assert dst[3] == 1 #this has been copied from src assert dst[6] == 1 #this has not been replaced since src[4:8] is 0
Landed in rev. 3309