I realized I can't just type something like @x with the writeln function. Is HexStr(@x) the right approach? And no matter how many times I run the program in Pascal I always get as an address numbers between 0,1,2s. That doesn't look ok when comparing with C's hex value.
I've tried also with the format function with the same result. Maybe because I'm on windows.. I don't know if that's the case.
Output:
Value of x: 100 Address of x: 0000000100021010
I realized I can't just type something like @x with the writeln function. Is HexStr(@x) the right approach? And no matter how many times I run the program in Pascal I always get as an address numbers between 0,1,2s. That doesn't look ok when comparing with C's hex value.
It all depends are where the respective compilers/linkers are allocating these variables, and whether they are from the stack or the heap.
And no matter how many times I run the program in Pascal I always get as an address numbers between 0,1,2s. That doesn't look ok when comparing with C's hex value.
PS C:\fpc\git> .\testoutput\tvar.exe
00007FF61183C010
PS C:\fpc\git> .\testoutput\tvar.exe
000000010000C010
In C language I can easily print a variable's address just by using the & operator.you can code the above _almost_ exactly the same in FPC under Windows using NTDLL's sprintf.
In C language I can easily print a variable's address just by using the & operator.you can code the above _almost_ exactly the same in FPC under Windows using NTDLL's sprintf.
basically, instead of a printf call, use sprintf(yourcharbuffer, <same stuff as printf>) with @x instead of &x followed by a writeln(yourcharbuffer);
You are aware that YiannisKam's question is mainly about the value of the address itself and not about printing it?Yes, I just wanted to show that he can take the address and print it (or use it) in FPC almost exactly as it is done in C. IOW, depending on the code he uses (e.g, sprintf), he won't need to call HexStr(@x) or something equivalent.