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

Add extern “C” block to header files #533

Merged
merged 1 commit into from
Jul 9, 2024
Merged

Conversation

MarkoPura
Copy link
Contributor

By adding an extern "C" block to header files, we avoid linking problems when building C++ applications that come from name mangling since C++ supports function overloading.

@MarkoPura MarkoPura self-assigned this Jul 3, 2024
Copy link

github-actions bot commented Jul 3, 2024

Visit the preview URL for this PR (updated for commit 04f5e6b):

https://golioth-firmware-sdk-doxygen-dev--pr533-add-cpp-suppor-vt4iqsxd.web.app

(expires Wed, 10 Jul 2024 15:50:10 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: a9993e61697a3983f3479e468bcb0b616f9a0578

Copy link

github-actions bot commented Jul 3, 2024

Code Coverage

Type Coverage
lines 56.9% (1273 of 2238 lines)
functions 64.9% (126 of 194 functions)

Copy link
Collaborator

@mniestroj mniestroj left a comment

Choose a reason for hiding this comment

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

I get why include/golioth/*.h files need that. But how about src/*.h? Those are private and should not be built with C++ compiler.

@MarkoPura
Copy link
Contributor Author

I agree @mniestroj and was debating with myself whether to add it to src/*.h files or not. I've left it there in the end since it "doesn't hurt", but I can always remove it.

@@ -3,6 +3,12 @@
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifdef __cplusplus
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this also required in the private headers? Or only in the public headers? These headers in src/ aren't available to user applications, so they will only be included by C files, not C++.

Copy link
Contributor Author

@MarkoPura MarkoPura Jul 3, 2024

Choose a reason for hiding this comment

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

I'll remove it from the private headers in src/

@mniestroj
Copy link
Collaborator

I agree @mniestroj and was debating with myself whether to add it to src/*.h files or not. I've left it there in the end since it "doesn't hurt", but I can always remove it.

IMO it does hurt :) Any additional code that is not used is a dead code. Dead code not tested and potentially not working. Even if that is only so small, #ifdef __cplusplus will never be true.

So I opt for removing it from private headers.

By adding extern "C" block to header files, we avoid linking
problems when building C++ applications that come from name
mangling since C++ supports function overloading.

Signed-off-by: Marko Puric <marko@golioth.io>
@MarkoPura
Copy link
Contributor Author

@sam-golioth, @mniestroj removed from the src/ folder!

Copy link
Contributor

@sam-golioth sam-golioth left a comment

Choose a reason for hiding this comment

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

Thanks @MarkoPura!

@MarkoPura MarkoPura merged commit ee39e9b into main Jul 9, 2024
43 of 44 checks passed
@MarkoPura MarkoPura deleted the add-cpp-support branch July 9, 2024 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants