42. Resolve UART Namespaces

#include <iostream>
using namespace std;

// Bootloader UART driver
namespace Boot {
    namespace UART {
        void send() {
            cout << "BOOT UART";
        }
    }
}

// Application UART driver
namespace App {
    namespace UART {
        void send() {
            cout << "APP UART";
        }
    }
}

int main() {
    int mode;
    cin >> mode;

    if (mode == 1) {
        Boot::UART::send();
    }
    else if (mode == 2) {
        App::UART::send();
    }

    return 0;
}

Explanation & Logic Summary:

  • Both drivers define a function named send()
  • Nested namespaces (Boot::UART and App::UART) prevent naming conflicts
  • The input mode determines which UART driver function is invoked

Firmware Relevance & Real-World Context:

  • Bootloaders and application firmware often maintain separate drivers
  • Embedded projects frequently encounter symbol name collisions
  • Namespaces are a clean, zero-overhead solution in embedded C++
  • This mirrors real modular firmware architecture and code isolation practices

 

 

 

 

Loading...

Input

1

Expected Output

BOOT UART