News for hackers. Stuff that matters.
Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by hwc on Friday January 24, 2020 @11:08AM (#22139438)
A common issue with C++ software is the need for a stable, standard ABI, which C provides but C++ does not (except through `extern "C"`). Because C++ name mangling is not standardized and the standard library headers have tons of implementation-specific details, something like `void foo(std::unique_ptr<Bar>);` does not have a stable ABI.
Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by jcranmer on Friday January 24, 2020 @12:03PM (#22140110)
In practice, there is a stable and standard ABI in C++. On Windows systems, you use the (undocumented, but mostly reverse-engineered) MSVC ABI. On everybody else, you use the confusingly-named Itanium ABI, except for exception handling on ARM, which uses a slightly different ABI.

Standard library implementations do not necessarily share the same ABI, but it is possible to interoperate between libc++ and libstdc++, and libstdc++ maintains ABI compatibility across different versions.

And, to be pedantic, C does not provide a stable, standard ABI. It is the platforms themselves that provide this ABI standard, and these platforms equally provide a C++ ABI standard. So C++ ABI compatibility is no more or less a problem than C ABI compatibility.

Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by paulddraper on Friday January 24, 2020 @02:45PM (#22141762)
The legitimate difference between C and C++ ABIs is that the C ABI is easier to understand and reason about.

It's analogous to Java and Scala; each has an ABI, but it's easier to tell when the former breaks ABI than the latter.

Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by likeliv on Friday January 24, 2020 @05:49PM (#22143139)
That's right. C being more limited, it has a more simplistic ABI. But the parent comment was replying the "need for a stable, standard ABI, which C provide". Which is misleading as both C++ and C have the same level of stability and standardisation of their ABI. (I.e: none of them is standardized, but both of them are stable on practice)
Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by paulddraper on Friday January 24, 2020 @06:22PM (#22143325)
Yep, you're right.

There is a difference, but the difference is in complexity, not availability.

Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by pjmlp on Friday January 24, 2020 @01:26PM (#22141029)
Just a small correction macOS derived platforms do it a bit differently as well.
Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by adev_ on Friday January 24, 2020 @11:37AM (#22139790)
> common issue with C++ software is the need for a stable, standard ABI.

That's not entirely true. C++ has a stable ABI: compiling a library with GCC and reusing it with clang or ICC is doable and commonly done nowadays.

The problem with the C++ ABI is that it is shamefully fragile. It is extremely easy to break an ABI without wanting it in C++, even for experts.

https://community.kde.org/Policies/Binary_Compatibility_Issu...

Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by zabzonk on Friday January 24, 2020 @11:39AM (#22139808)
> standard ABI, which C provides but C++ does not

Neither the C Language Standard nor the C++ Language Standard specify an ABI.

Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by DoofusOfDeath on Friday January 24, 2020 @12:50PM (#22140655)
> Neither the C Language Standard nor the C++ Language Standard specify an ABI.

Perhaps we should distinguish between a Langage-Standard ABI vs. a per-platform de facto ABI.

I think the GP's comment holds for the latter definition.

Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by zabzonk on Friday January 24, 2020 @01:10PM (#22140874)
I don't believe that either the GCC or MSVC C ABIs have been the same (per platform) over the years.
Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by temac on Friday January 24, 2020 @02:51PM (#22141815)
For C: both platform have been EXTREMELY compatible over the years. They probably both treat breakage as bug. This is a must given the fundamental APIs are defined in term of C headers, and must remain compatible.

Even for C++: gcc has been mostly compatible, but not unreasonably so. MSVC was traditionally not at all, but has recently been for 2 or 3 major versions in a row. I think MSVC will eventually break it again though, but at least they break it way less often than before (and breaking can also have advantages).

Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by BubRoss on Friday January 24, 2020 @11:34AM (#22139754)
What does that have to do with lifetime annotations?
Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by jcelerier on Friday January 24, 2020 @11:31AM (#22139706)
how is that related in any way to the article ?
Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by Someone on Friday January 24, 2020 @11:47AM (#22139920)
Also, I don’t think there is anything in the C, respectively C++ standards that forbids, respectively requires name mangling. Linking isn’t specified in either standard.

C++ implementations have name mangling because they live on systems designed for C, which don’t allow symbols such as int max(int,int)

C implementations (would) need name mangling if they ran on a system that used case-insensitive comparisons on symbol names, or on ones whose character set is smaller than that allowed in C symbols (I know examples of neither, but Wikipedia has an example that encodes the calling convention in the symbol name: https://en.wikipedia.org/wiki/Name_mangling#C)

Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by ape4 on Friday January 24, 2020 @12:23PM (#22140353)
The table in that article shows how different compilers mange very similarly but not the same! This is something that could be standardized for the benefit of all.
Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by Someone on Friday January 24, 2020 @02:07PM (#22141388)
Not quite. You would know what to call, but not how to call it. That would require full ABI compatibility, and C++’s is complex. https://isocpp.org/wiki/faq/compiler-dependencies#binary-com...:

”If name mangling was standardized, could I link code compiled with compilers from different compiler vendors?

Short answer: Probably not.”

(click link for more info)

Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by jcelerier on Friday January 24, 2020 @03:30PM (#22142149)
> Probably not.

yet the real life answer is that I can link C++ code built with three different compiler on linux (gcc / clang / icc) and three / two on windows (clang / cl.exe / icc or clang / gcc)

Re:The C++ Lifetime Profile: How It Plans to Make C++ Code S... by ape4 on Friday January 24, 2020 @02:46PM (#22141778)
Thanks for the info. I'm just a C/C++ user. There has to be way to workout a convention for all those options.