Compile-Time Timer Reload

#include <iostream>
#include <cstdint>
using namespace std;
#define timerClockHz 1000000

// Define constexpr computeReload here
constexpr uint32_t computeReload(unsigned int intervalMS)
{
    return ((timerClockHz * intervalMS + 500) /1000);
}
// Define constexpr RELOAD_TABLE here
constexpr uint32_t RELOAD_TABLE[3]={computeReload(1),computeReload(10),computeReload(100)};

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

    // Print RELOAD_TABLE[idx]
    cout << RELOAD_TABLE[idx];

    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Expected Output

1000