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

Explicit cast from void* to corresponding type #4

Merged
merged 6 commits into from
Jun 24, 2019
Merged

Conversation

iakov
Copy link
Contributor

@iakov iakov commented Jun 5, 2019

Fix compilation without -fpermissive
Originally was PR signal11/hidapi#430

Fix compilation without -fpermissive
@Qbicz
Copy link
Member

Qbicz commented Jun 5, 2019

In C, void* should be promoted to any pointer type without problem. Do you really compile this code with C++ compiler?

mac/hid.c Outdated Show resolved Hide resolved
@Youw
Copy link
Member

Youw commented Jun 5, 2019

In C, void* should be promoted to any pointer type without problem

At certain compilation flags, even C compiler can start giving warning for the implicit pointer casts, which becomes a real problem with -Werror or smth.
For some projects that's a big dial, and they might use builds systems of their own.

@LudovicRousseau
Copy link
Member

Please provide a copy of a C (not C++) compiler warning for this case.
See also https://en.wikipedia.org/wiki/C_dynamic_memory_allocation#Type_safety

For my own code I always include the warning or error message reported by the compiler in the commit message. So that it is clear what problem is solved when reviewing the PR or the commit 10 years later.

@iakov iakov force-pushed the master branch 2 times, most recently from ca647f5 to d3af10b Compare June 6, 2019 07:46
@Youw
Copy link
Member

Youw commented Jun 6, 2019

My first thought was about -Wconversion which, apparently isn't the case for malloc (i.e. casting from void*) and C compiler.

There is -Wc++-compat which is quite verbose regarding compatibility with C++, and it gives me a second thought.

@iakov why do you need have the ability to compile this source using C++ compiler?

Copy link
Member

@Qbicz Qbicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide the warning text that is being fixed in commit message?

@iakov
Copy link
Contributor Author

iakov commented Jun 6, 2019

Well, yes, my fault. We use C++ as a main language for https://github.com/trikset/trik-studio , and */hid.c files were included into .cpp, so it is a C++ related issue. Nevertheless, if this does not blow up code, and looks correct from pure C point of view, I hope these edits are useful for those like me (who includes .c files into C++ code).

Copy link
Member

@Youw Youw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not get use to follow C best practices, so I wouldn't make a last call on this.

But I don't consider including .c/.cpp files in other .c/.cpp files as a good practice unless absolutely necessary.

Although, I don't see anything strictly wrong with this changes.

mac/hid.c Outdated Show resolved Hide resolved
mac/hid.c Outdated Show resolved Hide resolved
Qbicz
Qbicz approved these changes Jun 7, 2019
libusb/hid.c Show resolved Hide resolved
iakov and others added 2 commits June 8, 2019 16:32
I prefer explicit INVALID rather than possible compiler warning about uninitialized var sometimes later
libusb/hid.c Outdated Show resolved Hide resolved
libusb/hid.c Outdated Show resolved Hide resolved
@Qbicz Qbicz merged commit c022f55 into libusb:master Jun 24, 2019
@mcuee mcuee added hidraw Related to Linux/hidraw backend libusb Related to libusb backend macOS Related to macOS backend labels Jul 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hidraw Related to Linux/hidraw backend libusb Related to libusb backend macOS Related to macOS backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants