Boost logo

Boost :

From: Simon Buchan (simon_at_[hidden])
Date: 2005-10-20 22:14:55

Scott Schurr wrote:
> Reece Dunn wrote:
>>Have you tried an approach that does not use enums. You can
>>either use a maximum-size integer:
> Let me give you a little background. One of my goals for
> this template is for it to take no space. I've been writing
> C++ code for embedded systems. It's important to me that the
> conversion from binary to hex (or whatever) happen entirely at
> compile time, leaving no trace in the object file.
> The advantage of enums is that they are guaranteed to occupy
> no space. If I start using integers, even static const integers,
> the compiler has the choice of leaving some number of those
> in the object code. I'm trying to avoid that.
> At any rate, that's my justification for using enums instead
> of the largest integer for my calculations. I hope now I'll learn
> why integers are okay, since there are template metaprogramming
> experts listening.
Any C++ compiler worthy of the name won't allocate it unless you require
it to have an address (the obvious way is to &foo :-), in which case you
cannot put it inline with the class anyway (at least, according to the
Standard). The whole point of allowing 'static const int foo = ...' was
to have an explicit replacement for the 'enum hack'.

Note that Stroustrop uses the enum hack, according to TC++PL3E (well, my
memory of it, at least).

Boost list run by bdawes at, gregod at, cpdaniel at, john at