SuperC documentation

⚠️ Namespace are implemented up-stream, but the playground does not support it yet

Namespaces

Big code projects must support namespaces to organize large codebases. So SuperC will not survive without namespacing.

Namespaces are not intended to reduce the amount of typing, but to organize the code and prevent name collisions.

But in order to keep it simple and avoid “namespace hell”:

Identifier names

SuperC allows the use of :: inside identifier names (but not single character :, as that would conflict with label parsing)


#pragma namespace

Instead of constantly typing foo:: before all the identifiers in your header files, you can use #pragma namespace foo, this assigns the name prefix to foo::.

Same as name prefix, there is also a symbol prefix (see #pragma namespace_symbol)

Note: the #pragma namespace directive replaces the previous one. If you invoke #pragma namespace foo and then #pragma namespace bar, the namespace is not foo::bar, it’s bar. Use #pragma namespace foo::bar to indicate a nested namespace.

#pragma namespace_symbol

Reduce deep namespace identifiers

You can use a macro to reduce deep nested namespaces in some cases.

#define Arithmetic Math::Algebra::Arithmetic
printf("%d\n", Arithmetic::Add(1, 2)); // equivalent to Math::Algebra::Arithmetic::Add

Examples


Previous

Soft objects (OOP)
Playground