Victor Bazarov wrote:
> Jonathan Mcdougall wrote:
>>>-------------------------------------------------- Speckey.h
>>>#ifndef SPECKEY_INCLUDED
>>>#define SPECKEY_INCLUDED
>>>
>>>struct specialkey {
>>> ...
>>>};
>>>
>>>#endif
>>>-------------------------------------------------- Globals.h
>>>#ifndef GLOBALS_INCLUDED
>>>#define GLOBALS_INCLUDED
>>>
>>>#include <Speckey.h>
>>
>>
>># include "speckey.h"
>
>
> First of all, you misspelled the header, the first letter of the file
> name is an 'S' and not an 's'.
That's true, but it may or may not matter, that's
implementation defined.
> Second, angle brackets or double quotes
> are often interchangeable,
How often, I wonder?
> and the use of them is implementation-defined
> anyway.
Also true, but a name between angle brackets does
not necessarily represent an actual source file
and it would be legal for an implementation to
reject these directives even if they worked with
double quotes. That's what most modern compilers do.
What point are you trying to make here?
>Third, the existence or absence of whitespace
between '#' and
> 'include' is a personal preference.
And of course wasn't the point of the "correction".
> Considering all that, I do not see
> how your "correction" is valid.
Seriously?
>>By the way, to the OP, globals are best avoided.
>
> It is often pointless to give such recommendation without an explanation.
Here we go (in no particular order and non
exhaustive).
Because global objects can be accessed from
anywhere within a program, tracking every of their
use and predicting their state at a given point is
difficult.
Their order of construction (and therefore
destruction) is undefined across translation units
and the programmer must rely on several dirty
tricks to make sure one global object can use
another. These tricks are often non portable and
"inefficient".
The Singleton pattern has often been used as a
disguised global object and even if the access is
more secure (since it is done via a function), the
drawbacks are still the same.
Exceptions thrown by global objects are not catchable.
Finally, when two modules share a global object,
it makes it more difficult to reuse only one of them.
But don't get me wrong. I didn't say global
objects *must* be avoided, I said globals are best
avoided. There are some designs in which they are
preferable/more "efficient"/mandatory.
> Care to provide one?
I would prefer the tone of the discussion to stay
(become?) friendly or at least polite
Jonathan