Initializing pointer location with a constant

I am creating a program for a DSP processor. I have a bunch of static addresses and registers which are required to read and write from. So, I would like to assign a name to each address to make the programming easier and clearer to read. The problem is I cannot find a way to assign the pointer's location address to the value of the constant.

Does any one know a way or a better method to accomplish this?
Last edited on
So you are saying that
1
2
3
4
5
// C code
unsigned char* p = (unsigned char*)0x12345;

// C++ code
unsigned char* p = reinterpret_cast <unsigned char*> (0x12345);

don't work?
Sorry, I am very new to this. I have never used C for this before, I had C courses a long time ago and have reviewed the language tutorial on this site. I have been using assembly for other projects.

I have a port at memory location 0x90090040 and want to relate to it as a constant name say USB_port.

and I will want to write a value to it or read a value from it.

1
2
3
4
5
6
7
8
9
10
11
const unsigned int USB_data=0x90090040;

void main(void){
 
unsigned int *p;

p=USB_data;

*p=10;
  
}


This is what I would think would have worked for setting the value of the pointer, but it will not compile. I get this:error: a value of type "unsigned int" cannot be assigned to an entity of type "unsigned int *"

What you proposed does compile, but I do not understand its use. I am not using strings.

Memory location would be an unsigned integer. The pointer's address value represents what ???? (an entity?). I would be writing a hex value to the location or register (unsigned integer?)



Last edited on
Ah. Thanks. Just use the constant directly, and make it of the correct type:
1
2
3
4
5
6
7
unsigned int* const USB_data = (unsigned int*)0x90090040;

int main()  // main ALWAYS returns int!
  {
  *USB_data = 10;  // place the value 10 at the address
  ...
  }

Hope this helps.
Thanks Duaos, that was it.
Topic archived. No new replies allowed.