472,325 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,325 software developers and data experts.

A constant integral


When you have a constant integral in a program, like the population of a
town, how do you declare it? A const variable or an enum?

Up until now I've always used variables, e.g.:

unsigned const population_dublin = 8274816;
I'm flipping through pages of Bjarne's book though at the moment, and
enum's seem pretty handy, as in:

enum { population_dublin = 8274816 }
Which style would you advocate?

-Tomás
Mar 3 '06 #1
1 1998
Tomás wrote:
When you have a constant integral in a program, like the population of a
town, how do you declare it? A const variable or an enum?
Whatever floats your boat.
Up until now I've always used variables, e.g.:

unsigned const population_dublin = 8274816;
Is it really 'const'? I wonder, nobody is born and nobody dies in Dublin?
I'm flipping through pages of Bjarne's book though at the moment, and
enum's seem pretty handy, as in:

enum { population_dublin = 8274816 }
Which style would you advocate?


The former unless you need to place it in a class (as 'static') and your
compiler is too old to support integral static const initialisation in the
class definition.

V
--
Please remove capital As from my address when replying by mail
Mar 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Keith | last post by:
I receive compiler error messge: "integral constant expression expected" for: somefunc(char *bar) { char foo; } Is there any way around...
13
by: hn.ft.pris | last post by:
Hi: I have the following simple program: #include<iostream> using namespace std; int main(int argc, char* argv){ const double L = 1.234;...
3
by: _Christopher\(M2M\) | last post by:
Microsoft Visual Studio 2005 Version 8.0.50727.762 (SP.050727-7600) How do I get rid of "Warning C4307: '-' : integral constant overflow" from...
1
by: Claire | last post by:
"Comparison to integral constant is useless; the constant is outside the range of type 'int'" How can I fix this compiler warning, please, for the...
13
by: Szabolcs | last post by:
Is the following legal? void fun(int N) { int arr; } gcc and Digital Mars accept it, but msvc complains that it wants a constant expression.
8
by: johnehein | last post by:
#include <vector> using namespace std; template <typename Iter> int foo(Iter first, Iter last, int nn) { const size_t n = last - first;...
3
by: Dan Smithers | last post by:
What constitutes a constant-expression? I know that it is something that can be determined at compile time. I am trying to use template code and...
7
by: Hendrik Schober | last post by:
Hi, this #include <string> class test { typedef std::string::size_type size_type; static const size_type x = std::string::npos; }; doesn't...
56
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.