Namespaces in C (Renamable libraries)

Channel:
Subscribers:
6,130
Published on ● Video Link: https://www.youtube.com/watch?v=mhlUSGZKtco



Duration: 2:11
3,511 views
103


Here's my idea for how to approximate namespaces in C. Please let me know what you think, and if you have other ideas I'm all ears! Namespaces encompass several different aspects, and I only captured one here, so if a different part of namespaces is more important to you, I invite your ideas on how to implement them.

The code needed for namespacing (edit this to suit your needs):

#define NAMESPACE_MY_LIBRARY_WITH_A_LONG_NAME ml_

#pragma push_macro ("C")
#pragma push_macro ("C_")
#pragma push_macro ("N")

#define C_(a,b) a##b
#define C(a,b) C_(a,b)
#define N(a) C(NAMESPACE_MY_LIBRARY_WITH_A_LONG_NAME, a)

// All your code goes here, using N(NameOfThing) to name functions, types and variables.

#pragma pop_macro ("C")
#pragma pop_macro ("C_")
#pragma pop_macro ("N")

Chapters:
00:00 Overview
00:11 The namespacing macros
00:46 Namespacing things throughout a library
01:23 Using a namespaced library
01:58 Welcoming your ideas and opinions