Page MenuHomeFreeBSD

ctld: Convert to C++
ClosedPublic

Authored by jhb on Feb 26 2025, 3:54 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Apr 15, 1:15 AM
Unknown Object (File)
Sun, Apr 13, 3:05 AM
Unknown Object (File)
Tue, Apr 8, 1:11 AM
Unknown Object (File)
Sun, Apr 6, 9:14 AM
Unknown Object (File)
Wed, Apr 2, 6:44 PM
Unknown Object (File)
Mar 19 2025, 12:47 PM
Unknown Object (File)
Mar 19 2025, 9:31 AM
Unknown Object (File)
Mar 17 2025, 8:12 AM
Subscribers

Details

Summary

This is the minimal set of changes need to compile as C++ so git can
handle the rename correctly.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Feb 26 2025, 3:54 PM

A few functions, like conf_set_debug, will now be extern "C" in the header file, but not in their implementation. It might work, but I don't think it's right. Also, conf.c seems to have two purposes. It defines C functions used by parse.y, and it also defines C functions used by ctld.cc. Maybe we should leave conf.c as a C file, but move some its ctld functions into ctld.cc itself? OTOH, if you're going for "minimal set of changes necessary to build as C++, it would be easier just to move those prototypes out of the "extern C" section.

Hmm, my assumption is that the extern "C" for the prototype is sufficient for the compiler to use the "C" symbol for the function when compiling conf.cc, but that permits using C++ constructs in conf.cc. In the future these methods in conf.cc will be invoking methods on C++ objects so it needs to be a conf.cc file, just that the symbols exported from it use C symbol names (not mangled).

Hmm, cppreference.com has an explicit example of this case that it says is fine:

https://en.cppreference.com/w/cpp/language/language_linkage

In particular:

A redeclaration of an entity without a linkage specification inherits the language linkage of the entity and its type (if exists).

Followed by this example:

extern "C" int g();
int g(); // OK, has C language linkage
A redeclaration of an entity without a linkage specification inherits the language linkage of the entity and its type (if exists).

Ahh, good find!

This revision is now accepted and ready to land.Mar 18 2025, 6:22 PM
This revision was automatically updated to reflect the committed changes.