I'm a bit confused about how to handle const with a double pointer.
I have a function which needs to take a pointer to a u8* so it can change the location the pointer points to, but it does not actually modify any data pointed to by the u8*, so I have made it const, like so:
void foo(const u8** ptr)
{
// ...do something useful...
*ptr += some_int;
}
This compiles just fine, but I cannot pass a non-const pointer to it, as the compiler won't automatically promote it to const:
void bar()
{
u8 *hoge;
foo(&hoge); // <- cannot convert parameter 1 from 'u8 **__w64 ' to 'const u8 **'
}
According to the
CPP FAQ Lite this isn't allowed, and the solution is to use this format instead:
void foo(const u8* const* ptr)
Unfortunately doing so makes the pointer ptr const as well, and I get a compile error telling me that *ptr += some_int; is const and can't be modified.
What is the best solution to this problem?