Seeing this thread I wrote the following: How do I convert from void * back to int
#include <iostream>
#include <stdlib.h>
using namespace std;
int main (int argc, char *argv[])
{
void* port = (void*) atoi (argv[1]);
cout << "\nvalue: \n" << atoi (argv[1]) << "\n";
int h = *((int *)port);
cout << h;
}
output:
anisha@linux-dopx:~/> ./a.out 323
value:
323
Segmentation fault
anisha@linux-dopx:~/>
GCC
What’s the point that I am missing?
Okay, please ignore my previous answer. Instead of
(char*)port - (char*)0, please do the following:You’re getting the address of
port:Casting the address to an
int *:Then dereferencing the address to get back the integer value you put into
port: