[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: insert-header-preprocessor-definition

From: Yuri Khan
Subject: Re: insert-header-preprocessor-definition
Date: Mon, 16 Apr 2018 12:35:36 +0700

On Mon, Apr 16, 2018 at 2:46 AM, Emanuel Berg <address@hidden> wrote:
>> The practical solution is, of course, the
>> same as with all name conflict issues:
>> Namespacing. That is, in your project, you
>> start all preprocessor defines with the name
>> of your project.
> Woah, is *that* what people mean with
> "namespacing"? I thought that was something
> more advanced!

Well, yes, I define namespacing as the means to subdivide a _space_ of
_names_ into subspaces so that names from different subspaces are
guaranteed to not clash. Each such subspace is a _namespace_.

Many languages and environments have first-class support for
namespaces. For example, in the UNIX file system, a directory is a
namespace. In C++, a fully qualified name starts with ::, followed by
namespace names separated by ::, followed by an identifier.

> I remember people using it in C++ and I removed
> it telling everyone it was a bad idea and
> instead one should use the whole path to
> identify things.

Some languages let programmers access all names in a namespace as if
they were local. In C++, “using namespace foo;”; in Python, “from foo
import *”; etc. By many coding standards and conventions, these are
discouraged, because they make it harder to reason about the complete
set of names accessible at a point, and where each name comes from.

In small scopes, wholesale importing a namespace is okay, and
sometimes even necessary.

>> On the other hand, the two or three compilers
>> out there that are most likely to be used to
>> compile your project already support
>> #pragma once.
> I'm on gcc 4.9. Should I get away with the
> guards and use '#pragma once' instead? says GCC has
supported #pragma once since 3.4.

Of course, when you work in a team, such decisions are best taken collectively.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]