Anonymous | Login | Signup for a new account | 2025-09-22 11:28 UTC | ![]() |
My View | View Issues | Change Log | Roadmap | Doomseeker Issue Support Ranking | Rules | My Account |
View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
0003802 | Doomseeker | [All Projects] Bug | public | 2020-06-07 01:44 | 2021-08-07 16:52 | ||||
Reporter | WubTheCaptain | ||||||||
Assigned To | Blzut3 | ||||||||
Priority | low | Severity | trivial | Reproducibility | have not tried | ||||
Status | closed | Resolution | won't fix | ||||||
Platform | OS | OS Version | |||||||
Product Version | 1.3.1 | ||||||||
Target Version | Fixed in Version | ||||||||
Summary | 0003802: C system headers are included from C++ source files without extern "C" | ||||||||
Description | Some unknown obscure old C libraries might not support C++, like so:#ifdef __cplusplus extern "C" { #endif void foo(); #ifdef __cplusplus } #endif The C++ standard inherits some standard C headers, which are available as <cxxx> and <xxx.h>. The latter is deprecated in the standard, but available for compatibility. But the C++ standard doesn't speak of non-standard C system .h headers, such as <windows.h> or <unistd.h> (from POSIX.1 operating system, based on C standard). There is no C++ equivalent (no <cunistd> in C++ STL or POSIX). So should they use extern "C" in the program? The C++ standard says extern "C++" is assumed by default. Doomseeker doesn't wrap these C headers in extern "C". | ||||||||
Steps To Reproduce | Two examples from Doomseeker:Quote from src/core/main.cpp#ifdef Q_OS_OPENBSD #include <unistd.h> #endif Quote from src/core/main.cpp#ifdef USE_WINMAIN_AS_ENTRY_POINT #include <windows.h> /* ... */ #else /* ... */ #endif | ||||||||
Attached Files | |||||||||
![]() |
|
WubTheCaptain (reporter) 2020-06-07 01:47 edited on: 2020-06-07 02:14 |
Honestly this is so trivial because every modern C library I looked at (glibc-2.30, musl-1.2.0 (git HEAD, actually), dietlibc-0.34) implements standard and non-standard headers with extern "C" via #import <sys/cdefs.h> (with __BEGIN_DECLS and __END_DECLS macro). So I didn't bother to fix this immediately without feedback / resolution first. This issue exists because of those... obscure C libraries that may or may not exist in practice anymore. But I'm pedantic. Imo, ignoring what those modern C standard/system libraries do, I think it's better for libraries and programs to do: /* foo.h */ void foo(); /* foo.cpp */ extern "C" { #include "foo.h" } int main() { foo(); return 0; } while this is bad practice imo: /* foo.h */ #ifdef __cplusplus extern "C" { #endif void foo(); #ifdef __cplusplus } #endif /* foo.cpp */ #include "foo.h" int main() { foo(); return 0; } Yes, the latter is cleaner for modern programs utilizing modern system libraries. But the prior is perhaps more portable (and correct). |
WubTheCaptain (reporter) 2020-06-07 01:57 |
(assume "foo.h" would be a C system library <foo.h> in the above note) |
WubTheCaptain (reporter) 2020-06-07 02:18 edited on: 2020-06-07 02:21 |
If this is "won't fix" for the code, I'd rather make a documentation note somewhere for a C++ compiler / C library requirements. We're going to remain depending on those C headers. |
WubTheCaptain (reporter) 2020-06-07 07:37 edited on: 2020-06-07 07:38 |
'https://developers.redhat.com/blog/2016/02/29/why-cstdlib-is-more-complicated-than-you-might-think/ [^]' Suggests to look back into 1998. Quote |
Pol M (developer) 2020-06-07 21:17 |
I honestly think that most modern C programs have the extern "C" guard. If we ever encounter such an issue, we can create an "include_[library].h" header that puts the guard around the desired header. That said, I've seen <string.h> somewhere, and that can be changed without issues to cstring (same goes for similar cases) :) |
WubTheCaptain (reporter) 2020-06-07 23:01 edited on: 2020-06-07 23:02 |
Quote from Pol M There is Doomseeker's own string handling header, strings.hpp. It conflicted with glibc's <string.h>. See 0003385. Quote from src/core/strings.hpp The only remaining <string.h> is in LZMA (not in our code). So I'm also not sure if or what you're proposing. |
Blzut3 (administrator) 2020-06-08 00:50 |
The suggestion goes against the coding practices of literally every other C++ program in the wild. I see why you would come to the conclusion that the program doing extern "C" instead of the library is more correct, but that's just not how the world decided to solve the problem. Probably because extern "C" only solves the name mangling problem and doesn't solve other issues with using C headers like potential use of reserved key words. So the header needs to be polyglot anyway. |
Pol M (developer) 2020-06-08 12:34 |
Quote from Sub True, my bad :) |
This issue is already marked as resolved. If you feel that is not the case, please reopen it and explain why. |
|
Supporters: | No one explicitly supports this issue yet. |
Opponents: | No one explicitly opposes this issue yet. |
![]() |
|||
Date Modified | Username | Field | Change |
2020-06-07 01:44 | WubTheCaptain | New Issue | |
2020-06-07 01:47 | WubTheCaptain | Note Added: 0021358 | |
2020-06-07 01:48 | WubTheCaptain | Note Edited: 0021358 | View Revisions |
2020-06-07 01:49 | WubTheCaptain | Summary | C headers are included without extern "C" => C headers are included from C++ source files without extern "C" |
2020-06-07 01:50 | WubTheCaptain | Note Edited: 0021358 | View Revisions |
2020-06-07 01:52 | WubTheCaptain | Note Edited: 0021358 | View Revisions |
2020-06-07 01:53 | WubTheCaptain | Note Edited: 0021358 | View Revisions |
2020-06-07 01:57 | WubTheCaptain | Note Added: 0021359 | |
2020-06-07 02:00 | WubTheCaptain | Steps to Reproduce Updated | View Revisions |
2020-06-07 02:00 | WubTheCaptain | Steps to Reproduce Updated | View Revisions |
2020-06-07 02:03 | WubTheCaptain | Note Edited: 0021358 | View Revisions |
2020-06-07 02:14 | WubTheCaptain | Summary | C headers are included from C++ source files without extern "C" => C system headers are included from C++ source files without extern "C" |
2020-06-07 02:14 | WubTheCaptain | Note Edited: 0021358 | View Revisions |
2020-06-07 02:18 | WubTheCaptain | Note Added: 0021360 | |
2020-06-07 02:21 | WubTheCaptain | Note Edited: 0021360 | View Revisions |
2020-06-07 03:43 | WubTheCaptain | Priority | none => low |
2020-06-07 07:37 | WubTheCaptain | Note Added: 0021368 | |
2020-06-07 07:38 | WubTheCaptain | Note Edited: 0021368 | View Revisions |
2020-06-07 21:17 | Pol M | Note Added: 0021393 | |
2020-06-07 21:17 | Pol M | Status | new => feedback |
2020-06-07 23:01 | WubTheCaptain | Note Added: 0021399 | |
2020-06-07 23:01 | WubTheCaptain | Status | feedback => new |
2020-06-07 23:02 | WubTheCaptain | Note Edited: 0021399 | View Revisions |
2020-06-08 00:50 | Blzut3 | Note Added: 0021402 | |
2020-06-08 00:50 | Blzut3 | Status | new => resolved |
2020-06-08 00:50 | Blzut3 | Resolution | open => won't fix |
2020-06-08 00:50 | Blzut3 | Assigned To | => Blzut3 |
2020-06-08 12:34 | Pol M | Note Added: 0021431 | |
2021-08-07 16:52 | Blzut3 | Status | resolved => closed |
Copyright © 2000 - 2025 MantisBT Team |