Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Standard format 1

Status
Not open for further replies.

JasonWB007

Programmer
Dec 21, 2005
14
0
0
US
Hi everyone,

Please forgive the simple question, but if I have a declaration, such as:

const int UPPER_LIMIT = 127;

is the *best* policy to have it in caps? I usually do it in:

#define UPPER_LIMIT 127

and am wondering if the same thing should apply to a const variable?

Thoughts?

Jason
 
It depends on what you are going to use UPPER_LIMIT for. For instance if you want to code the following without casting or having strange compilation warnings
Code:
unsigned char w = UPPER_LIMIT;
char x = UPPER_LIMIT;
unsigned int y = UPPER_LIMIT;
int z = UPPER_LIMIT;
int elems[UPPER_LIMIT];

if (x == UPPER_LIMIT)...

for (x = 0; x < UPPER_LIMIT; ++x)...

switch (x)
{
case UPPER_LIMIT:
   ...
}
then #define is better. If you are just using it for
Code:
int z = UPPER_LIMIT;
int* elems = new int[UPPER_LIMIT];

if (z == UPPER_LIMIT)...
then const int is better.
 
Sorry, about the original post - I think I was less than clear. I ONLY an referring to a constant declaration. The reason I ask is that our coding standards for DO-178B recommend using "const" over "#define" and I had always used all caps for #define, but not const. This is probably a very "strict" formatting question.
 
I always use all caps for const variables as well as #define's.
I also use p for pointers, m_ for member variables and usually C for class names or I for interfaces...
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top