Question about header conventions

closed account (iw0XoG1T)
I have a question about headers. I read the article about headers from this website and it recommended a method to keep from including headers twice. After reading the article it occurred to me that I have never had a problem with headers. So I took a look at my include file and found that all the headers I use regularly are wrapped.

But I noticed this convention:
1
2
3
4
5
6
7
8
#ifndef _GLIBCXX_VECTOR
#define _GLIBCXX_VECTOR 1

#pragma GCC system_header

// removed this section

#endif /* _GLIBCXX_VECTOR */ 


What does the "1" in
#define _GLIBCXX_VECTOR 1
mean and why is it used?
Last edited on
#define _GLIBCXX_VECTOR 1
defines _GLIBCXX_VECTOR as a preprocessor constant with value 1,
#define _GLIBCXX_VECTOR
would be the same but without any value
see http://www.cplusplus.com/doc/tutorial/preprocessor/
closed account (iw0XoG1T)
I guess I should have been more clear; is there a good reason for assigning the value of 1, and more importantly is this something I should be doing?
Not necessarily. It is a convention used by the GCC. I do not know whether the value 1 is significant to the GCC or not, but it could be.

However, your headers should typically be of the form:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* filename.hpp
 * product name/short description
 * copyright
 * license
 */

#pragma once
#ifndef UNIQUE_ID_FILENAME_HPP
#define UNIQUE_ID_FILENAME_HPP

#include <stuff>
#include <morestuff>

#include "etc"

namespace my_namespace
  {
  types and typedefs
  external constant declarations
  function prototypes
  etc
  }

#endif 

Hope this helps.
Last edited on
closed account (iw0XoG1T)
Thank you for the example--yes it does help.
Topic archived. No new replies allowed.