Item 2, Scott Myers Effective C++ question

Posted by user619818 on Programmers See other posts from Programmers or by user619818
Published on 2012-04-01T19:57:35Z Indexed on 2012/04/01 23:39 UTC
Read the original article Hit count: 480

Filed under:

In Item2 on page 16, (Prefer consts, enums, and inlines to #defines), Scott says:

'Also, though good compilers won't set aside storage for const objects of integer types'.

I don't understand this. If I define a const object, eg

const int myval = 5;

then surely the compiler must set aside some memory (of int size) to store the value 5?

Or is const data stored in some special way?

This is more a question of computer storage I suppose. Basically, how does the computer store const objects so that no storage is set aside?

© Programmers or respective owner