consts in C++ have the property you describe.
Code:
$ cat foo.cpp
#include <iostream>
using namespace std;
const int ANSWER = 42;
const int QUESTION = 24;
void foo ( const int *ptr ) {
cout << *ptr << " " << ANSWER << endl;
}
int main ( ) {
const int *ptr = &QUESTION;
foo(ptr);
}
$ g++ -S -O2 foo.cpp
$ egrep 'QUESTION|ANSWER|42|24' foo.s
.LFB824:
.LFE824:
.cfi_def_cfa_offset 24
.cfi_offset 3, -24
movl $42, %esi
movq -24(%rax), %rax
movq 240(%rbp,%rax), %rbx
.cfi_def_cfa_offset 24
movl $_ZL8QUESTION, %edi
.type _ZL8QUESTION, @object
.size _ZL8QUESTION, 4
_ZL8QUESTION:
.long 24
Unless you do weird things like point at them, the compiler will just use the known value without ever allocating storage for it.