473,699 Members | 2,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

novice question

I'm looking at some codes I wrote five years ago when taking a C++
course. Having not touched C++ since, I have forgotten most of it.
Now I can't even comprehend my own codes.

I have a question:

What does these two lines in the attached header file do? I
vaguely remember there is something special about the underscores.

#ifndef __RECORD__
#define __RECORD__

///////////////////////////// Record.h
////////////////////////////////////
// Declare a Record struct to be used in file.h
////////////////////////////////////////////////////////////////////////////
#include "utildll.h"
////////////////////////////////////////////////////////////////////////////
//
// Record struct - contains 4 fields: Name, SSN, Birthdate, State
//
////////////////////////////////////////////////////////////////////////////
#ifndef __RECORD__
#define __RECORD__

struct Record
{
char cName [21],
cSSN [12],
cBirthdate [9],
cState [3];

}; // end of Record structure

#endif
Oct 6 '05 #1
9 1792
John Smith wrote:
I'm looking at some codes I wrote five years ago when taking a C++
course. Having not touched C++ since, I have forgotten most of it.
Now I can't even comprehend my own codes.

I have a question:

What does these two lines in the attached header file do? I
vaguely remember there is something special about the underscores.

#ifndef __RECORD__
#define __RECORD__


a) these two lines are inclusion guards. Everything up to the matching
#endif is included only once.

b) double underscores in identifiers are reserved for the compiler and the
standard library that comes with it. You must not use those in macros of
your own.
Best

Kai-Uwe Bux

Oct 6 '05 #2
* John Smith:

What does these two lines in the attached header file do?

#ifndef __RECORD__
#define __RECORD__
Those are preprocessor directives. Combined, they ensure that the text in
this file is only included once in each compilation unit. #ifndef tells the
preprocessor to pass on subsequent text to the compiler proper only if the
specified symbol isn't yet defined (this effect lasts until the corresponding
#endif), and #define defines the symbol so that next time around, if this file
is included again somewhere later in this compilation unit, the text is
guaranteed to be ignored, not passed on to the compiler proper.

I vaguely remember there is something special about the underscores.


Yes, names with two underscores are reserved for the implementation. So that
name is a bad one. It may happen to be defined by some standard header.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Oct 6 '05 #3
John Smith wrote:
I'm looking at some codes I wrote five years ago when taking a C++
course. Having not touched C++ since, I have forgotten most of it.
Now I can't even comprehend my own codes.

I have a question:

What does these two lines in the attached header file do?
They prevent multiple inclusions of the file, because only the first time
through is __RECORD__ not defined. The #ifndef tests whether it's not
defined, and the #define defines it so the test fails if the file is
included again.
I
vaguely remember there is something special about the underscores.
Yes, you aren't supposed to use leading underscores in names. They are
reserved for the compiler and its supplied libraries' own names.

#ifndef __RECORD__
#define __RECORD__

///////////////////////////// Record.h
////////////////////////////////////
// Declare a Record struct to be used in file.h
//////////////////////////////////////////////////////////////////////////// #include "utildll.h"
//////////////////////////////////////////////////////////////////////////// //
// Record struct - contains 4 fields: Name, SSN, Birthdate, State
//
//////////////////////////////////////////////////////////////////////////// #ifndef __RECORD__
#define __RECORD__
Normally these would be at the very top (without the leading underscores).
Otherwise you might be unnecessarily, or wrongly, including anything that's
above them more than once (in this case the #include "utildll.h" ).

struct Record
{
char cName [21],
cSSN [12],
cBirthdate [9],
cState [3];

}; // end of Record structure

#endif


DW
Oct 6 '05 #4
John Smith wrote:
I'm looking at some codes I wrote five years ago when taking a C++
course. Having not touched C++ since, I have forgotten most of it.
Now I can't even comprehend my own codes.

I have a question:

What does these two lines in the attached header file do? I
vaguely remember there is something special about the underscores.

#ifndef __RECORD__
#define __RECORD__

#endif


.........The #ifndef directive is mainly used to prevent multiple
definitions in a header file. For eg. consider a header file (with a
function defined in it) included in two other header files or two
source files. This will lead to multiple inclusions of same code (as
seen by compiler).

To avoid this, we use above directives....f or the first inclusion the
#ifndef returns true but for second inclusion the #ifndef returns
false.

AFAIK, there is nothing special about underscores, they are used only
to make sure the name used is unique. You can also try MYRECORD.
HTH,
Hemanth

Oct 6 '05 #5
Kev
Kai-Uwe Bux <jk********@gmx .net> wrote in
news:di******** **@murdoch.acc. Virginia.EDU:
b) double underscores in identifiers are reserved for the compiler and
the standard library that comes with it. You must not use those in
macros of your own.


I didnt know this. I always had the underscores because thats what I
generally saw often. Usually just the name of the file... minus the dot.
What kind of problem could this potentially cause?
Oct 6 '05 #6
Kev wrote:
Kai-Uwe Bux <jk********@gmx .net> wrote in
news:di******** **@murdoch.acc. Virginia.EDU:

b) double underscores in identifiers are reserved for the compiler and
the standard library that comes with it. You must not use those in
macros of your own.

I didnt know this. I always had the underscores because thats what I
generally saw often. Usually just the name of the file... minus the dot.
What kind of problem could this potentially cause?


Double underscores are reserved for the compiler so it can define it's
own macros. If the compiler had defined a macro __RECORD__ that would
interfere with the macro you had defined yourself.

Unfortunately there is a lot of bad C++ code around and a lot of people
copying code. It's better to understand C++ that just copy it, this is a
good place for gaining understanding.

John
Oct 6 '05 #7
"Kai-Uwe Bux" <jk********@gmx .net> wrote in message
news:di******** **@murdoch.acc. Virginia.EDU...
b) double underscores in identifiers are reserved for the compiler and the
standard library that comes with it. You must not use those in macros of
your own.


As I understand the standard, a single underscore in the OP's case would
also be out:
17.4.3.1.2
1 Certain sets of names and function signatures are always reserved to the
implementation:
- Each name that contains a double underscore (_ _) or begins with an
underscore followed by an uppercase letter (2.11) is reserved to the
implementation for any use.

DW

Oct 6 '05 #8
Kev
John Harrison <jo************ *@hotmail.com> wrote in news:2o41f.1070 2
$h******@newsfe 2-gui.ntli.net:

Unfortunately there is a lot of bad C++ code around and a lot of people
copying code. It's better to understand C++ that just copy it, this is a
good place for gaining understanding.


True. But then we all learn by seeing what others have done. At least in
the beginning. Great artists are no different until they develop their own
skills. In fact there is a controversial theory, with some controversial
'evidence', that the great masters traced much of their work by using
mirrors and projections which were invented around the same time.
Supposedly xplaining why the proportions in their paintings are so perfect.
But I digress ;o)

I suppose it also explains the other examples I have seen that include very
long strings of random number-letter combinations, and why VC++ always does
it for pregenerated headers. As far I can tell from my limited experience
anyways. I have as of yet had no such problems in my wee little programs.
But I shall change them.

Thnx
Oct 6 '05 #9

"Kev" <di************ **@pht.zzz> wrote in message
news:Xn******** **************@ 216.168.3.44...
John Harrison <jo************ *@hotmail.com> wrote in news:2o41f.1070 2
$h******@newsfe 2-gui.ntli.net:

Unfortunately there is a lot of bad C++ code around and a lot of people
copying code. It's better to understand C++ that just copy it, this is a
good place for gaining understanding.
True. But then we all learn by seeing what others have done.


But we can be misled if we not sure exactly what it is
that those others have done, and in this case exactly
who has done it. You were most likely looking at what
an implementor did. There are rules in place which govern
what an implementor or a program author can do. Some of
these rules reserve certain forms of tokens for the implementor
so that they can be assured that there are no name clashes
(if the program author also adheres to the rules).

At least in
the beginning. Great artists are no different until they develop their own
skills. In fact there is a controversial theory, with some controversial
'evidence', that the great masters traced much of their work by using
mirrors and projections which were invented around the same time.
Supposedly xplaining why the proportions in their paintings are so
perfect.
But I digress ;o)

I suppose it also explains the other examples I have seen that include
very
long strings of random number-letter combinations, and why VC++ always
does
it for pregenerated headers. As far I can tell from my limited experience
anyways. I have as of yet had no such problems in my wee little programs.
But I shall change them.


Such problems don't tend to occur until a critical time
(such as when the program gets demonstrated or delivered
to clients) :-)

-Mike
Oct 6 '05 #10

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

Similar topics

7
1731
by: Christopher Richards | last post by:
It is possible to be able to receive email alerts (say, from Google News) and publish them to a web page automatically? I am a novice as far as PHP goes, but I can open and write to a file and close the file up again. The html page references the file and can format the plain text. So far I am OK ( I think ). I am not sure how I would automate, or get the content of the email, and output it to a file. Any thougths? Thank you.
5
2366
by: Marian | last post by:
Hi, I am totaly novice in .NET and I am studying a book about this. There was mentioned "assembly". I did not understand, how function does it has . I would like to know the exact run of code (intermediate language and so on). Is there any page on internet, which makes me clear? Thanx
2
2011
by: George | last post by:
Is this group for a novice C++ programmers?
21
2932
by: AES/newspost | last post by:
My understanding -- I'm not an expert -- is that on (some? many? all?) standard Internet servers a URL can point to a subdirectory name followed by a backslash, and that links to this URL will automatically go to an "index.html" file located in that subdirectory, if there is one. Q1: Is this more or less correct? At least some HTML texts also recommend using this as the basis for organizing a web site: Put the web pages associated...
6
3438
by: ronwer | last post by:
Hello, The title doesn't completely cover the question I have, but it's a bit more complicated problem we have. We are using a database, based on Acces, but developed by a third party developer who sells it under his own name. So, functionally it's a very specific database for a specific purpose. Now we want to make certain changes in this database, but for reasons of
3
2237
by: herrcho | last post by:
Here is the code.. #define NAME "MEGATHINK, INC" #define ADDRESS "10 Megabuck Plaza" #define PLACE "Megapolis, CA 94904" int main() { starbar(); printf("%s\n",NAME);
2
2259
by: Dmitry Sazonov | last post by:
I'm novice here and I'm sorry for stupid question. We are trying to understand web services architecture, is it better than TIBCO.Randevouz and does webservices fit our needs. I understand, I can make web servce and a client applicaiton. Client will call the service and will receive some kind of responce. But can my client applicaiton receive EVENT from web service? Can I "subscribe" to, let say, "Clock" web service and web service...
1
2542
by: Christo | last post by:
I have a question please this is just theory at the moment I am a novice java programmer Is it possible for me to write information to a hashmap and then once it has been written to extract a certain piece of information in that hash map and store it in a variable then manipulate the information stored in the variable and then put the information from the variable back into the hashmap in the place that i got
1
2999
by: TwistedSpanner | last post by:
Hello all, For the record I am a complete java novice. I have to write a program to generate/output to screen 10 simple maths question and output a final score . The question is as follows Random number, Random operator (+ or -) random number. I have written the program but cannot make the random operator work. Can anyone help? My code.
9
3054
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped. Below you will find the code I've written and the error that results. I'm hoping that someone can give me some direction as to what syntax or parameter is missing from the code that is expected by VBA. Overview: I'm trying to copy calculated...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8905
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.