Namespaces in C (Renamable libraries)
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
Other Videos By Nick Walton
2023-08-16 | C Programming on Manjaro Linux Quick Setup Guide |
2023-07-02 | Draw Text in C with Bitmap Fonts |
2023-01-10 | Pixel Perfect Collision Detection in C |
2022-11-05 | Easy C Debugging with VSCode & GDB |
2022-10-01 | Namespaces in C (Renamable libraries) |
2022-07-09 | Multi-Threaded Game Framework in C |
2022-05-07 | High Precision Timing on Windows in C |
2022-04-02 | Load .WAV Sound Files in C |
2022-03-26 | Load .BMP Images in C |
2022-02-27 | Realtime Sound on Windows in C with WinMM |
2022-02-18 | Win32 Input in C (Keyboard/Mouse) |
2022-02-11 | GCC/MinGW on Windows Quick Setup Guide |
2022-02-01 | Draw Pixels to a Win32 Window in C with GDI |
2022-01-21 | Open a Window in C with Win32 |
2021-12-26 | C Programming on Windows Quick Setup Guide |
2020-03-12 | Switching to C - One Year Later |
2019-11-24 | I was sent Ben Eater's 6502 computer kit! |
2019-10-03 | Super Kero Land Early Access Trailer! |
2019-07-10 | The big Notemon delay |
2019-04-24 | Maze95 Launch Trailer |
2019-04-13 | Welcome to Nyoo Owtearowa - Notemon Trailer |