Return pointer from void only gives the memory address

Joined
Nov 24, 2024
Messages
1
Reaction score
0
Good day,

I want to build some wrapper .dll and part of it is to extract data from a void function and pass it on. So its possible to pass something vi a pointer or a global value. But with *(& fptr) I can only get the address of the variable, whereas inside the function *(& fptr) actually returns the value of the variable.
Yet In the debugger the memory address contains the value until the last line, return (); , so it should still be there at sdt::cout

What else needs doing?


Code:
#include <iostream>
double voidfilled1{};

void* pointer(double inptr)
{
    double voidFunctPtr{};
    voidFunctPtr = inptr+3;
    std::cout << "inside funct is float: " << voidFunctPtr << ", &voidFunctPtr: "<<  &voidFunctPtr << ", *(&voidFunctPtr) :"<< *(&voidFunctPtr) << '\n';
    voidfilled1 = voidFunctPtr;
    return &voidFunctPtr;
}

int main() {

    double ptr{3.3};
    double* fptr = (double*) pointer(4.6+4);
    double retrieved{};
    std::cout << "content of main is " << ptr << " in funct: "<< &fptr << " global: "<< voidfilled1 << " *(&fptr):" << *(& fptr) << '\n';
    return 0;
}

yields this. But *(& fptr) should yield 11.6?

inside funct is float: 11.6, &voidFunctPtr: 000000A11E2FF7E8, *(&voidFunctPtr) :11.6
content of main is 3.3 in funct: 000000A11E2FF928 global: 11.6 *(& fptr):000000A11E2FF7E8
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,075
Messages
2,570,545
Members
47,197
Latest member
NDTShavonn

Latest Threads

Top