#include <iostream>
using namespace std;
namespace Communication {
namespace I2C {
int speed = 400000; // 400 kHz
}
}
int main() {
namespace CI = Communication::I2C;
cout << "I2C Speed: " << CI::speed;
return 0;
}
Explanation & Logic Summary:
namespace CI = Communication::I2C; creates a namespace alias- Instead of writing
Communication::I2C::speed, we can write CI::speed - This improves readability without changing behavior
Layman’s Terms
It’s like creating a shortcut to a deep folder so you don’t have to navigate the full path every time.
Firmware Relevance & Real-World Context
Embedded projects often use deeply nested namespaces for hardware abstraction layers (HALs), drivers, and protocols.
Namespace aliasing improves readability and reduces clutter in firmware code while preserving structure.