P
puzzlecracker
Large scale C++ software design, by John Lakos - people any good
recommendations to this book?
recommendations to this book?
puzzlecracker said:Large scale C++ software design, by John Lakos
- people any good recommendations to this book?
what would you supplement this book with? Any viable alternatives orE. Robert Tisdale said:This book was published in 1996
and contains a lot of obsolete advice.
For example, Chapter 2 Ground Rules,
Section 5 Redundant Include Guards, page 85,
Minor Design Rule
Place a redundant (external) include guard
around each preprocessor include directive
in every header file.
Today, we expect the C preprocessor to remember
idempotent header files and read them only once.
E. Robert Tisdale said:This book was published in 1996
and contains a lot of obsolete advice.
For example, Chapter 2 Ground Rules,
Section 5 Redundant Include Guards, page 85,
Minor Design Rule
Place a redundant (external) include guard
around each preprocessor include directive
in every header file.
Today, we expect the C preprocessor to remember
idempotent header files and read them only once.
Shezan Baig said:What are you talking about?
Is that specified in standard C++?
Does
the following code compile for you?
blah.h
------
int somefunction() { return 9; }
blah.cpp
--------
#include <iostream>
#include "blah.h"
#include "blah.h"
int main() { std::cout << somefunction() << std::endl; }
I tried it on gpp and got "error: redefinition of 'int
somefunction()'". If it compiles for you, I'd really like to know what
compiler you're using.
Shezan said:What are you talking about?
Is that specified in standard C++?
Does the following code compile for you?
blah.h
------
int somefunction() { return 9; }
blah.cpp
--------
#include <iostream>
#include "blah.h"
#include "blah.h"
int main() { std::cout << somefunction() << std::endl; }
I tried it on gpp
and got "error: redefinition of 'int somefunction()'".
If it compiles for you,
I'd really like to know what compiler you're using.
#ifndef GUARD_BLAH_H // *internal* include guardcat blah.h
#include <iostream>cat blah.cpp
Victor said:However, if you add
#pragma once
to 'blah.h', some modern compilers will not preprocess it
again. The existence of 'once' pragma makes *external*
include guards unnecessary.
Victor said:No, what you presented here will certainly not compile.
However, if you add
#pragma once
to 'blah.h', some modern compilers will not preprocess it
again. The existence of 'once' pragma makes *external*
include guards unnecessary.
puzzlecracker said:Large scale C++ software design, by John Lakos - people any good
recommendations to this book?
E. Robert Tisdale said:John Lakos might write:
#ifndef GUARD_BLAH_H // *internal* include guard
#define GUARD_BLAH_H 1
int somefunction() { return 9; }
#endif//GUARD_BLAH_H 1
#include <iostream>
#ifndef GUARD_BLAH_H // *external* include guard
#include "blah.h"
#endif//GUARD_BLAH_H
#ifndef GUARD_BLAH_H // *external* include guard
#include "blah.h"
#endif//GUARD_BLAH_H
int main() { std::cout << somefunction() << std::endl; }
The redundant external include guards are not necessary
because, after the C preprocessor reads blah.h once,
it remembers that blah.h is idempotent
and it won't even attempt to read it a second time.
Ioannis said:Still it can not be considered portable, and I wonder why at least the
2003 standard did not include this directive.
No, redundant guards go in the .h file only, not in the .cpp file.
Mike said:Well, then, they're not *redundant*, now, are they?
Dietmar said:They are: the idea is that you enclose each '#include' statement
in a header file with the same guards as the header file uses
internally. That is, if you omit the redundant guards, there will
be no semantic difference.
Mike said:And once you omit the redundant guards, then they can no longer be
*redundant*. The ones in the .cpp file are the redundant ones; once you
remove them, you're left with the ones in the .h file, which are *not*
redundant.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.