If I declare in a header file, for example, extern unsigned long * Ptr; and the value of this pointer Ptr in the linker file. Will this adrress be 'constant'? Can I change its value ?

  • 1
    What happened when you tried it in a short 20 line test program? – Dan Pichelman Nov 11 '13 at 18:33
  • What do you mean by "this pointer"? The address of Ptr, like the address of any declared object, does not change. The address contained in Ptr can be changed to anything you like by assigning a value to it. (Your title mentions the const keyword, but you don't actually ask about it.) – Keith Thompson Nov 11 '13 at 18:41
  • Yes it's true; I have not used the “const” keyword. I'd say that if we just wrote extern unsigned long * Ptr; and in the linker file (not in the source files) we Add Ptr=0x0012FFEE. This means that the address 0x0012FFEE and its value are constant (like if I wrote extern const unsigned long * Ptr)? – physics Nov 12 '13 at 9:37
extern unsigned long *Ptr;

You can write to both Ptr (point to a new object) and *Ptr (update the thing being pointed to).

extern const unsigned long *Ptr;
extern unsigned long const *Ptr;

You can write to Ptr (point to a new object), but you cannot write to *Ptr.

extern unsigned long * const Ptr;

You can write to *Ptr (update the thing being pointed to), but you cannot write to Ptr.

extern const unsigned long * const Ptr;
extern unsigned long const * const Ptr;

You cannot write to either Ptr or *Ptr.

In all cases, the value of &Ptr does not change.

Naturally, this assumes a matching defining declaration for Ptr.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.