Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with ... error: invalid conversion from ‘void*’ to ‘void**’ #13

Closed
brewmanz opened this issue Apr 22, 2017 · 5 comments
Closed

Comments

@brewmanz
Copy link

@brewmanz brewmanz commented Apr 22, 2017

I was getting

/usr/include/csptr/smart_ptr.h: In function ‘void sfree_stack(void*)’:
/usr/include/csptr/smart_ptr.h:33:23: error: invalid conversion from ‘void*’ to ‘void**’ [-fpermissive]
     void **real_ptr = ptr;
                       ^
make: *** [src/Test.o] Error 1

which I fixed by changing line
void **real_ptr = ptr;
to
void **real_ptr = (void**)ptr;

@Snaipe
Copy link
Owner

@Snaipe Snaipe commented Apr 22, 2017

The problem is innocent enough that I could include the fix, but it makes no sense on a standard point of view: in C99, void * is implicitely convertible to any other pointer type. What compiler and build flags are you using here?

@brewmanz
Copy link
Author

@brewmanz brewmanz commented Apr 22, 2017

I'm actually compiling it as C++ (g++ under Ubuntu) for unit testing some C code I'm writing, so I'd like it to be bilingual i.e. work in C and C++. I've ended up creating my own *.hpp headers from the *.h ones (which are now left untouched). By using '#if __cplusplus' and 'extern "C"' the *.h can probably be made bilingual, and mman.c being compiled under C (gcc).

@brewmanz
Copy link
Author

@brewmanz brewmanz commented Apr 29, 2017

By using #if __cplusplus, I've got rid of the *.hpp I created. The downside is that I've had to shift some header-only code into mman.c e.g. array_length.
(Maybe there's another way, but that was simplest for me).

@Snaipe
Copy link
Owner

@Snaipe Snaipe commented Apr 29, 2017

Right. Moving the inline functions from the headers to the .c is probably the best of both worlds.

@Snaipe
Copy link
Owner

@Snaipe Snaipe commented May 1, 2017

So it turns out that casting to void ** violates aliasing rules (since the original type can pretty much be any pointer type, not just the generic void *). Using an union rather than casting avoids this problem and makes C++ happy at the same time.

Snaipe added a commit that referenced this issue May 1, 2017
This also addresses partially #13.
@Snaipe Snaipe closed this in 5bc7aad May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants