MantisBT - Doomseeker |
View Issue Details |
|
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 |
Additional Information | |
Tags | No tags attached. |
Relationships | |
Attached Files | |
|
Issue History |
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 | bug_revision_view_page.php?bugnote_id=21358#r13107 |
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 | bug_revision_view_page.php?bugnote_id=21358#r13108 |
2020-06-07 01:52 | WubTheCaptain | Note Edited: 0021358 | bug_revision_view_page.php?bugnote_id=21358#r13109 |
2020-06-07 01:53 | WubTheCaptain | Note Edited: 0021358 | bug_revision_view_page.php?bugnote_id=21358#r13110 |
2020-06-07 01:57 | WubTheCaptain | Note Added: 0021359 | |
2020-06-07 02:00 | WubTheCaptain | Steps to Reproduce Updated | bug_revision_view_page.php?rev_id=13112#r13112 |
2020-06-07 02:00 | WubTheCaptain | Steps to Reproduce Updated | bug_revision_view_page.php?rev_id=13113#r13113 |
2020-06-07 02:03 | WubTheCaptain | Note Edited: 0021358 | bug_revision_view_page.php?bugnote_id=21358#r13114 |
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 | bug_revision_view_page.php?bugnote_id=21358#r13115 |
2020-06-07 02:18 | WubTheCaptain | Note Added: 0021360 | |
2020-06-07 02:21 | WubTheCaptain | Note Edited: 0021360 | bug_revision_view_page.php?bugnote_id=21360#r13117 |
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 | bug_revision_view_page.php?bugnote_id=21368#r13138 |
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 | bug_revision_view_page.php?bugnote_id=21399#r13154 |
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 |
Notes |
|
(0021358)
|
WubTheCaptain
|
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).
|
|
|
|
(assume "foo.h" would be a C system library <foo.h> in the above note) |
|
|
(0021360)
|
WubTheCaptain
|
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.
|
|
|
(0021368)
|
WubTheCaptain
|
2020-06-07 07:37
(edited on: 2020-06-07 07:38) |
|
|
|
(0021393)
|
Pol M
|
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) :) |
|
|
(0021399)
|
WubTheCaptain
|
2020-06-07 23:01
(edited on: 2020-06-07 23:02) |
|
Quote from Pol M That said, I've seen <string.h> somewhere, and that can be changed without issues to cstring (same goes for similar cases) :)
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 // Why hpp in this case? Glibc 2.26 changed string.h to include its strings.h
// so this file would shadow that header and cause errors.
The only remaining <string.h> is in LZMA (not in our code). So I'm also not sure if or what you're proposing.
|
|
|
(0021402)
|
Blzut3
|
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. |
|
|
(0021431)
|
Pol M
|
2020-06-08 12:34
|
|
Quote from Sub
The only remaining <string.h> is in LZMA (not in our code). So I'm also not sure if or what you're proposing.
True, my bad :) |
|