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

1

9

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++?

Ribble answered 10/4, 2013 at 22:4 Comment(0)
B
19

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.

Belt answered 10/4, 2013 at 22:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.