nowox
nowox

Reputation: 29096

How to assign constant to a pointer?

I would like to assign an address value to a pointer, but I get this warning:

#define PRODUCT_NUMBER_ADDR  0x12345

"foo\foo.c", line 1444: cc1967: {D} warning: "long *" pointer set to
          literal value - volatile needed?
              ram_address = (long*) (PRODUCT_NUMBER_ADDR);
                                     ^

How can I properly assign my address to my pointer?

Upvotes: 0

Views: 140

Answers (1)

ouah
ouah

Reputation: 145829

Change:

ram_address = (long*) (PRODUCT_NUMBER_ADDR);

to

ram_address = (volatile long*) (PRODUCT_NUMBER_ADDR);

Also make sure ram_address is declared as a volatile long *. Using volatile here tells the compiler the memory object can have its value changed unexpectedly and so the compiler should not make any cacheing assumption.

Upvotes: 4

Related Questions