Assigning Physical Values to Pointers in VC++

This is an old question that was never answered correctly. The problem may only apply to VC++ compiler - ??.

Cannot do this:

const unsigned int Port = 0x900E0000;
unsigned int *pData = Port; //Error - can't convert from int to int*.



Solution:
const unsigned int PORT = 0x900E0000;
const unsigned int PORT_PTR = ((unsigned int *)0x900E0000);
unsigned int *pData = PORT_PTR; //No Error.

I found no way to do it but the above.

Ex., you cannot do:

pData = (unsigned int *)0x900E0000;


Last edited on
1
2
3
const unsigned int PORT = 0x900E0000;
const unsigned int PORT_PTR = ((unsigned int *)0x900E0000);
unsigned int *pData = PORT_PTR; //No Error. 

I don't understand why you say // No Error. here. There are two definite errors. One on line 2 and one on line 3.


Ex., you cannot do:

pData = (unsigned int *)0x900E0000;

You most certainly can, although this uses a c-style cast that you should probably avoid in C++.

In C++:
unsigned int* const PORT_ADDRESS = reinterpret_cast<unsigned int*>(0x900E0000);
Topic archived. No new replies allowed.