Error[Pe513]: a value of type "void *" cannot be assigned to an entity of type "uint8_t *"

andre picture andre · Apr 11, 2013 · Viewed 15.9k times · Source

I am attempting to convert a C project into C++.

In the C project I countered this error while compiling into c++:

Error[Pe513]: a value of type "void *" cannot be assigned to an entity of type "uint8_t *"

The following code gives this error:

#define RAM32Boundary  0x20007D00
uint8_t *pNextRam;
pNextRam = (void*)RAM32Boundary;// load up the base ram

Can anyone explain what this is doing in C and how to convert it into C++?

Answer

Drew Dormann picture Drew Dormann · Apr 11, 2013

C allows implicit conversions to/from void*, which C++ does not. You need to cast to the correct type.

Use:

uint8_t *pNextRam;
pNextRam = (uint8_t*)RAM32Boundary;// load up the base ram

Or better still*, use a C++ style cast instead of C style.:

uint8_t *pNextRam;
pNextRam = static_cast<uint8_t*>(RAM32Boundary);// load up the base ram

*In practice, casting is an easy source of bugs. C++ style casts allow a reader of your code to easily see a cast and allow the compiler to enforce the correctness of your cast.