Board index » delphi » #ifndef _DICE_H

#ifndef _DICE_H

Hi Wayne,

I'm starting a new thread because my last note was unintentionally posted as
a reply to someone else's question.

I really appreciate the help on initializing a class, on using namespace
std, and on several other matters.  I'm happy to report that these programs
are now working as planned.  With regard to using classes, I realize I have
only a tenuous grasp, and that my success involves mostly emulating what I
read in Astrachan's book.

Please permit me to ask some other questions that came up during this
exercise.  For example, I read about the preprocessor directives, #ifndef,
#ifdef, and #endif in Help.  I think I understand the reasons for
conditional compilation, and how these directives are written.  What I am
unsure of is the connection between the name used in the #ifndef  statement
and the name of the class.  The first four lines of the \INCLUDE\DICE.H file
are included below.

Is it a requirement that _DICE_H be all upper case and that the underscores
be used as shown or is this just a convention?  What's the general rule for
the naming convention?  Under what keyword is this convention described in
Help?

The name _DICE_H is never explicitly used in any of the nodes or headers in
this project.  Please confirm that only the compiler ever sees the name
_DICE_H.

I don't yet have any appreciation for OOP, but that's because I haven't
developed a feel for it yet.  With your help, I intend to keep trying.

Thank you,

Ray Shapp
V5.02 Win98

#ifndef _DICE_H
#define _DICE_H

//  class for simulating a die (object "rolled" to generate
//                              a random number)

 

Re:#ifndef _DICE_H


Ray,

Quote
> Is it a requirement that _DICE_H be all upper case and that the underscores
> be used as shown or is this just a convention?  What's the general rule for
> the naming convention?  Under what keyword is this convention described in
> Help?

This is just a naming convention and not a requirement.  From what I was
taught, the two requirements are 1) the word is exactly the same for the
#ifndef and #define statements, and 2) the word needs to be unique for
each header file in your project.  Given these requirements, using the
file name each time is the easiest way to guarantee proper usage, and
using all caps just makes it more readable.  So if you really wanted,
you could use the names of Shakespearean characters in place of the file
names and things would still work the same; it'd just be harder to keep
track of and might annoy future programmers who use your code.

Bryan

Re:#ifndef _DICE_H


Quote
On Fri, 15 Feb 2002 09:37:25 +0100, Ray Shapp wrote:
> Is it a requirement that _DICE_H be all upper case and that the
> underscores be used as shown or is this just a convention?

On the contrary.

Names starting _[A-Z] or containing __ are reserved for the C++
implementation. You aren't allowed to give them meaning in user code.

Re:#ifndef _DICE_H


Hi Bryan and Thomas,

Thanks for your reply.  Can you tell me what section in v5.02 Help describes
the naming convention for preprocessor directives?  I'd like to see the
complete specification.  For example,  I'd like to learn about what is the
significance of one underscore in a name versus two successive underscores?
The only mention of naming conventions in a textbook I'm using (C++ 5 for
Dummies) describes "sentinels which are named H_nameofheaderfile.  Another
textbook (Lippmann & Lajoie) say the convention is that constants are
written in all upper case.

Regards,

Ray Shapp
Watchung, NJ

Re:#ifndef _DICE_H


In 'borland.public.cpp.borlandcpp', "Ray Shapp" <raysh...@erols.com>
wrote in news:3c6da189_2@dnews:

Quote
> Can you tell me what section in v5.02 Help
> describes the naming convention for preprocessor directives?  I'd like
> to see the complete specification.  For example,  I'd like to learn

There is not such a thing. However, the C (and C++) standard is clear
about what can be done or not. As previously told, the _DICE_H identifier
should not be used in an application header. Such names are reserved by
the standard for future use and implementations of the languages.

Better to use DICE_H or KJhFSDbNmlkyh if you prefer.

Quote
> about what is the significance of one underscore in a name versus two
> successive underscores? The only mention of naming conventions in a

There are reserved. An implementation and a future C or C++ standard are
free to define _DICE_H as macro, a type, an object, a function etc, which
will break your code.

A recent example is the introduction of the C identifier _Bool (Underscore
followed by an Uppercase) in the last version of the C language
(Nov.1999).

If you use DICE_H, such a thing will never happen.

Quote
> textbook I'm using (C++ 5 for Dummies) describes "sentinels which are
> named H_nameofheaderfile.  Another textbook (Lippmann & Lajoie) say the
> convention is that constants are written in all upper case.

It's indeed a wide spread practice.

--
-ed- emdel at noos.fr
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-library: http://www.dinkumware.com/htm_cl/index.html
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/

Re:#ifndef _DICE_H


Quote
On Sat, 16 Feb 2002 01:02:03 +0100, Ray Shapp wrote:
> Thanks for your reply.  Can you tell me what section in v5.02 Help
> describes the naming convention for preprocessor directives?

No. It's been years since I last used that compiler.

The rule I posted is from the ISO C++ Standard and the ISO C Standards.

Quote
> I'd like
> to see the complete specification.  For example,  I'd like to learn
> about what is the significance of one underscore in a name versus two
> successive underscores?

You are allowed to declare names containing underscores, but not two in a
row and not at the start of the identifier if the following character is
a capital letter (or another underscore, of course).

BTW: There are also limitations on other identifiers starting witha an
underscore, so the simple rule is not to declare such identifiers in user
code.

The reason for all this is that if the C++ implementation (particularly the
library) has to declare internal identifiers (e.g. of helper functions)
that mustn't clash with what the user is allowed to declare. E.g. this

#define BLABLA
#include <stdio.h>

is required to work (i.e. the Standard Library implementation mustn't get
disturbed by BLABLA being defined as a preprocessor symbol), but this
isn't:

#define _BLABLA
#include <stdio.h>

The Standard Library has the right to use the identifier _BLABLA
internally.

Quote
> The only mention of naming conventions in a textbook I'm using (C++ 5
> for Dummies) describes "sentinels which are named H_nameofheaderfile.
> Another textbook (Lippmann & Lajoie) say the convention is that
> constants are written in all upper case.

These are conventions. It's good to have them in professional development,
but the language doesn't enforce them.

Re:#ifndef _DICE_H


In 'borland.public.cpp.borlandcpp', Emmanuel Delahaye
<emdelNOS...@noos.fr> wrote in
news:Xns91B758A4EFAFAhsnoservernet@130.133.1.4:

Quote
> In 'borland.public.cpp.borlandcpp', "Ray Shapp" <raysh...@erols.com>
> wrote in news:3c6da189_2@dnews:

>> Can you tell me what section in v5.02 Help
>> describes the naming convention for preprocessor directives?  I'd like
>> to see the complete specification.  For example,  I'd like to learn

Found in comp.lang.c today:

[Brown 2001].   Brown, S., "Identifiers NOT To Use in C Programs".  Oak
Road Systems, Feb. 15, 2001.
`http://www.oakroadsystems.com/tech/c-predef.htm'.

--
-ed- emdel at noos.fr
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-library: http://www.dinkumware.com/htm_cl/index.html
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/

Other Threads