0

while I working with c++, I am getting some Axivion warnings while using casting operators, so I need some clarification about it, is it possible to change void* to unsigned int* ?

is there any solution for my problem?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
P B Pavan
  • 1
  • 1
  • 1
    No, implicit conversion from `void*` is not allowed in C++ in contrast to C. – Quimby Nov 30 '22 at 07:32
  • In C++ you should generally avoid `void*` pointers. Or any pointers, for that matter. Why do you have `void*`? What problem is that pointer supposed to solve? – Some programmer dude Nov 30 '22 at 07:35
  • You cannot implicitly cast it, unless you write your own implicit constructor/operator. You **can** however, use `reinterpret_cast(myVoidPtr)` to explicitely cast it. This would be the recommended way. – SimonC Nov 30 '22 at 07:35
  • See [void pointers: difference between C and C++](https://stackoverflow.com/questions/1736833/void-pointers-difference-between-c-and-c) – Jason Nov 30 '22 at 07:35
  • @Someprogrammerdude Especially when working with Linux and its syscalls, it's sometimes unavoidable to not use them. But I totally agree that they should be avoided at all costs. – SimonC Nov 30 '22 at 07:36
  • 1
    [In C++, conversions from `T*` to `void*` are implicit, but `void*` to anything else **requires a cast**.](https://stackoverflow.com/a/1736841/12002570) – Jason Nov 30 '22 at 07:36
  • Why is using casting operators a problem? If you want to avoid them for some reason then try not to use void pointers in the first place. – john Nov 30 '22 at 07:37
  • @SimonC -- re: "You cannot implicitly cast it" -- there is no such thing as an implicit cast; a cast is something you write in your source code to tell the compiler to do a conversion. The phrase you're looking for is "implicitly **convert** it". – Pete Becker Nov 30 '22 at 14:20
  • @PeteBecker If IBM is free to use the phrase "implicit cast", then I sure am, too – SimonC Nov 30 '22 at 15:14
  • @SimonC -- by all means, use muddy terminology and then explain what you meant by it, if that's what you like. – Pete Becker Nov 30 '22 at 16:10

0 Answers0