Last active
August 29, 2015 14:25
-
-
Save bogen/e1004c77dca781269a33 to your computer and use it in GitHub Desktop.
c pointers trunctaed when module importing related functions is not in the same module that is using them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import somePointerMod | |
let cptr = somePointer () | |
cptr.printPointer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ nim c badPointer.nim | |
config/nim.cfg(53, 3) Hint: added path: '/home/dwight/.babel/pkgs/' [Path] | |
config/nim.cfg(54, 3) Hint: added path: '/home/dwight/.nimble/pkgs/' [Path] | |
Hint: used config file '/home/dwight/nim/build/Nim/config/nim.cfg' [Conf] | |
Hint: system [Processing] | |
Hint: badPointer [Processing] | |
Hint: somePointerMod [Processing] | |
CC: badPointer | |
CC: stdlib_system | |
CC: somePointerMod | |
Hint: [Link] | |
Hint: operation successful (9561 lines compiled; 2.073 sec total; 14.143MB; Debug Build) [SuccessX] | |
$ ./badPointer | |
Original pointer: 0xff12345678 | |
Pointer is now : 0x12345678 | |
#if I don't import, but put everything in the same file, then no truncation... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{.emit: """ | |
void* somePointer () { | |
void* ptr = (void*) 0xFF12345678; | |
printf ("Original pointer: %p\n", ptr); | |
return ptr; | |
} | |
void printPointer (void* ptr) { | |
printf ("Pointer is now : %p\n", ptr); | |
} | |
""".} | |
type cPointer* = ptr object | |
proc somePointer* () : cPointer {.importc, noDecl.} | |
proc printPointer* (p: cPointer) {.importc, noDecl.} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment