0

I am writing unit tests for a driver code. To run the tests on the host platform, I created fake registers with the same name as used by driver on the actual target. Some of the driver function call has const volatile uint32_t* as a function argument. I do not understand why reinterpret_cast<const volatile uint32_t*>(address) returns 1. Is there any workaround? I appreciate your suggestions. For your reference, the issue can be replicated by below code. Thanks!

#include <iostream>
#include <cstdint>
using namespace std;
uint32_t g_register = 5;

void driverFunction(const volatile uint32_t* f_input){
    cout << f_input << " " << *f_input << "\n";
}

int main()
{
    uintptr_t l_regAddress = reinterpret_cast<uintptr_t>(&g_register);
    driverFunction(reinterpret_cast<const volatile uint32_t*>(l_regAddress));
    return 0;
}

p.s: I can not make any change in the driver code.

cigien
  • 57,834
  • 11
  • 73
  • 112
Toothless
  • 84
  • 6
  • 1
    It gets implicitly cast to `bool` when passed to `<<` operator, see: https://stackoverflow.com/questions/2501737/why-does-stdcout-convert-volatile-pointers-to-bool – alagner Oct 10 '21 at 10:29
  • @alagner Thank you very much for sharing that link. I understand now. – Toothless Oct 10 '21 at 10:41

0 Answers0