CppCast - C++ Extensions
Episode Date: September 12, 2019Rob and Jason are joined by Miro Knejp. They first discuss a blog post from Tanker covering their strategy to successfully use C++ for cross-platform mobile development. Then Miro gives them a preview... of his upcoming CppCon talk and tells us about some of the C++ extensions that are out there and probably won't ever be standardized. News Reacting to Dropbox: another take on cross-platform C++ development Tool Time 2019 Call for Open Content Sessions Student and Support Tickets for Meeting C++ 2019 Links Non-conforming C++: the Secrets the Committee is Hiding From You pinned_vector - Miro Knejp & Jakob Schweißhelm - Meeting C++ 2018 Sponsors Backtrace Announcing Visual Studio Extension - Integrated Crash Reporting in 5 Minutes JetBrains
Transcript
Discussion (0)
Thank you. Windows, mobile, and gaming platforms. Check out their new Visual Studio extension for C++ and claim your free trial at backtrace.io.
And by JetBrains,
makers of smart IDEs to simplify your challenging tasks
and automate the routine ones.
Exclusively for C++, JetBrains is offering a 25% discount
for a yearly individual license, new or update,
on the C++ tool of your choice,
CLion or Sharper C++ or AppCode.
Use the coupon code JETBRAINS for CppCast during checkout at www.jetbrains.com.
CppCast is also sponsored by CppCon, the annual week-long face-to-face gathering for the entire
C++ community.
Come join us in Aurora, Colorado, September 15th to 20th.
In this episode, we talk about one company's take on cross-platform mobile development.
Then we talk to Miro Kneipp.
Miro gives us a preview of his upcoming CppCon talk and the first podcast for C++ developers by C++ developers.
I'm your host, Rob Irving, joined by my co-host, Jason Turner.
Jason, how's it going today?
I'm all right, Rob. How are you doing?
Doing okay. It is the last week before CppCon,
where lots of people will be meeting up in Denver next week. Should be fun.
Yeah, and this episode will air basically as the conference is getting started effectively, right? Yeah, Friday right before the weekend where some people might be going a little
early to attend some of the classes, right? Right. Yeah, yeah. Anyone who's going to one of the pre-
weekend classes needs to be getting here pretty soon now. Yeah. Are you ready? I'm as ready as I
need to be. How about you though? You've a lot more to do next week compared to me.
Yeah, my week of busyness pretty much starts tonight with my local user group meeting,
and then I'm hosting the field trip, as we've talked about,
and three conference talks, and then a post-conference class.
I've given two of the talks once before each,
and the third talk will be completely brand new,
but fortunately that one's not until Friday.
So you still have to work on it.
Got a little bit of time to refine it if I need to.
I was actually just realized like last night as I was going to sleep that there
was a couple of slides I needed to add it to it.
So I made a note to do that.
Um,
yeah.
Okay.
Should be a busy week.
Which one is the completely new talk?
Uh, great C plus plus is trivial. Okay. Yeah. The, um be a busy week. Which one is the completely new talk? Great C++ is trivial.
Okay.
Yeah.
Let's see.
The best parts of C++ I gave as a keynote at Core C++ in Israel this year.
Right.
And then C++ Code Smells I just gave at Indice Tech Town in Oslo last week for the first time.
Nice. How was that conference, by the way?
It was good. It was interesting because it felt like a tiny venue, but it was still several
hundred people. And I don't know. I mean, it was just interesting to think like this is both a big
and small conference-ish at the same time. and there was like the people that I knew I kept running into over and over
again.
And the people that I didn't know,
I,
I basically didn't see,
I guess,
because it's like there was,
because it's a small venue,
you ended up kind of choosing the areas that you like to sit and congregate
in.
And then you kept seeing the same people over and over again.
And I didn't even realize that happened until someone else pointed it out to me.
I should have just gone to the other side of that wall
and I would have been able to meet other people, basically.
Right.
Okay.
Well, let's talk about a piece of feedback.
This week we got a tweet from Madam Young
saying, I just learned about CBBCast
while listening to Python Bytes,
which is a Python podcast.
I'm excited to check it out. Should I start
at the beginning, or is there a good point at which
to jump in? So yeah, I thought that
was pretty interesting that a Python podcast
mentioned us. Not really sure about the
context there. Yeah, me
neither, but I suggest that Madam Young start with
episode two. Episode two?
Skip the first
one just because you're the first i saw one other listener suggested um doing a memento style and
listening to the new episodes when they come out but continuing to go backwards in the catalog
i thought that was a that was an interesting idea you know know, except for like ClickGate, I don't know if we've really changed a whole lot over the years.
Presumably, we've gotten a little bit smoother.
Yeah, I mean, I think we've probably worked out a lot of issues
and improved a lot compared to the first year.
But then we also had a lot of really big-name guests that first year,
like Scott.
Yeah, Scott.
Myers. Andre. Andre, I think was in the first year like uh scott yeah scott myers um andre did he come andre i was in rescue
i think was in the first year yeah and then what episode 100 was when we had on bjarne
and that was that was 114 episodes ago yeah okay well we'd love to hear your thoughts about the
show uh you can always reach out to us on facebook
twitter or email us at feedback at cpcast.com and don't forget to leave us a review on itunes
or subscribe on youtube joining us today is miro knipe miro wrote his first line of c++ code in
1997 at the age of 12 and it has been his programming language of choice ever since
he is especially passionate about low-level programming, assembly,
3D graphics, and games engineering. Mira holds a master's degree in computer science from the Technical University of Munich. He has worked on products ranging from designing 3D rendering
libraries to building airport self-boarding control systems. He currently works as a freelancer and
trainer with the goal of creating his own video game one day. Mira, welcome to the show.
Hello, thank you for having me.
All right, I feel like there's two questions I have to ask about your bio.
The first is, what was your first programming language before C++?
It was a scripting language of a 3D engine that I'm not sure even exists anymore.
But that went away very quickly.
Not like Quake script or whatever?
It was like a German engine by some guy in Germany.
It was called the A4 engine, I think.
That's what we found in school.
But then we found OpenGL and C++ and went that way.
So you went from random, obscure, embedded scripting language to C++.
Yes.
Wow.
Okay, and then the other thing I have to ask is self-boarding control systems.
Is that like passengers stand on a conveyor belt and we get shoved into our seats? Yes. Wow. Okay, and then the other thing I have to ask is self-boarding control systems.
Is that like passengers stand on a conveyor belt and we get shoved into our seats?
Because that might be a real win for boarding airplanes.
No, that refers to when you board a flight, you put your boarding pass on a scanner and then it opens the door.
Yes.
Yes, so those systems.
And there's a lot.
They're very involved.
There's a lot attached to that. And so I'm mainly working on the, there's a PC in there,
and it controls all the attached peripherals
and communicates to the airline and stuff like that.
Okay.
I guess that, I said yes emphatically,
but that might require a little bit of background for our listeners.
It's not every airport that uses that kind of thing.
So yeah, you walk up to the gate
and you don't have to interact with a human at all.
You scan your boarding pass
and then you get to walk through, right?
Less human interaction.
It's always better.
Okay, so Mira, we got a couple of news articles to discuss.
Feel free to comment on any of these.
Then we'll start talking more about the talk of behaving as a pecan.
Okay.
Yep.
Okay.
So this first one is reacting to Dropbox.
Another take cross-platform C++ development.
So we did mention this Dropbox article.
I think it was maybe three or four weeks ago.
Jason, do you remember when that first came out?
It might have been about four weeks ago. And then we got we got the like we were trying to remember the burrito method
yeah and then oddy corrected us and yeah right right so dropbox unfortunately is dropping their
c++ support in favor of just doing uh you know the native platform language uh not Java, but Kotlin and Swift.
And this article is from Tanker, which I don't think I had heard of before,
but they're talking about the way they do C++ cross-platform development,
which does include mobile, and they've been successful with it.
Are you familiar with Tanker, Jason, before reading this article?
I am not.
Yeah, so it sounds like they do an encryption SDK.
So it is a little different compared to Dropbox, where they're making the whole mobile app.
It looks like Tanker provides an encryption SDK, which can be used by other mobile apps and I think also non-mobile platforms as well.
Right. apps and I think also non-mobile platforms as well. But they talked through some of the obstacles they've seen, but they
also just kind of rebutted a bunch of
the things said in the Dropbox
article, like kind of talking
about how Dropbox felt there
wasn't a good C++ open
source library ecosystem, which I think we both
disagreed with when we first read
the article, and they kind of highlighted it
with some data showing the number of active
repos in C++ and how it's been
going up really steadily
since 2013 when
Dropbox first started their C++ effort.
Yeah, actually...
Go ahead. Sorry. I was actually a
maintainer of Genie, the cross-platform
generator for a while. Oh, really?
So I was on the same boat.
I had a work where we created the 3D engine and it was supposed to run on both iOS and Android. Oh, really? big deal for us so we looked at genie and yeah somehow i got involved uh rewrote half the thing
for some reason they accepted the pull request i don't know why but then i became a maintainer for
about two years until i left the project yeah so i can totally understand their stance though
because we had the exact same project problem one of the teams were about to start a new application
and so we convinced them to also use c++ for the cross-platform code.
And yeah, getting mobile developers to use C++, it's difficult.
If they're only familiar with Objective-C and Java, then yeah, it's a challenge.
And as far as I know, the project, they stopped using it again
because the people there just don't want to use C++.
And it's also hard to find or hire mobile developers
who are willing to learn and dive into C++.
So yeah, I can totally understand why they made this decision.
I guess one of the things that made me think about with this article
was they're talking about how they have this SDK or library
that they make cross-platform with C++.
And maybe Dropbox could have had a little more success
if they treated it that way,
like kind of isolated the main Dropbox code,
which is doing lots of file I.O. and network I.O.
I would imagine, and put that in a shared C++ library.
But then the rest of the code, you know,
other business logic and GUI stuff
could be done in the native language.
It seems like that might be a better approach,
and you could still use something like Genie to make your platform bindings.
Yeah, I mean, that's how we used it, right?
So the platform teams all wrote the UI in the native frameworks,
and the shared business logic was written in C++,
and our 3D engine, which, of course, doesn't have any UI to it,
so that was a lot easier.
But, yeah, one difficulty we had was that Genie generates shared pointers
for its C++ interfaces everywhere.
And if you're not careful with that,
you end up with your entire business logic being littered with shared pointers.
And that's one of the things that really, I think,
created the problem of not wanting to deal with C++ by the mobile developers
because the shared pointers just polluted everything.
That's basically the world they live in with Java anyhow, right?
It is, right, but they don't see it. It's not in the language.
Okay.
So Objective-C with automatic reference counting, you just use normal pointers and you don't see all of this. Right. So this article says that they expose their API as a thin C interface.
And they say this is what Adi described in his salami method article.
And then that just makes it easier because JNI and all those things,
they like talking to C anyhow.
And any code that I've done that needed to be cross-language, cross-platform exposure, I did use Swig to bind, generate C++ bindings. I was just wondering if either of you
had experience with trying to do this thin C API exposure of your library, or if you did expose
C++. Sounds like you exposed C++ because you're talking smart pointers. Yeah, in this project, Genie, it was all smart pointers.
But a long time ago, I once created a.NET wrapper for a C++ library.
And that was mostly exposed through a C interface.
And then with C++ CLI on the other side, talking to both sides to the C API.
I just feel like, I mean, I don't know because because I've never done it, that there would be a,
unless it was a super, super high level interface,
there would be a lot of like,
create object, destroy object kind of things going on,
which sounds so painful.
Yeah.
I mean, on the Java side,
you have to hook into the garbage collector
to know when all the reference are gone
and then destroy the object.
If there are no C++ references to the shared pointer.
So, yeah, it's difficult.
And you have to fumble around with weak pointers
and weak references that aren't really exposed
in the Java language, right?
It's just library types.
It's not easy.
And on the C++ side,
you have the downside that
Genie would generate abstract base classes for you,
then you then had to implement
and that's how you expose your functionality and then that forced the whole shared pointer
and virtual stuff on you right so as a former genie maintainer do you still think you know if
you are gonna try to do this in mobile with shared c++ is it still a good option and it sounds like
dropbox probably won't be investing any more time in it.
Yeah.
I don't think I would go that way again because those
shared pointers,
I mean, I understand why they did it
because for the cross
platform reference counting
garbage collection stuff, but I think going
the C way is probably better
because they also tried
to create a Python integration,
which I don't think ever actually came out of alpha
or was ever released.
And I think languages are just better
at dealing with C interfaces.
So I think on both sides of the C barrier,
there's just more tools to deal with it.
That's my assumption at least.
Okay.
So we also have some articles from cpp con since it is going
to be next week uh the first one is that tool time is back i did they not have it last year
tool time jason they did they did okay but they did have it yeah so it's back for the second year
i believe is the point of this yes yeah so if you're not familiar with tool time, they're going to have a 90 minute session on Tuesday evening that is open to anyone that
wants to talk tools. And I think, um, you know, several like vendors will be there. It'll probably
be people from like JetBrains and Visual Studio to help people out if they have any questions
about their tools. That's kind of the, the point of this session, right, Jason?
Yeah. Uh, well it's,
you know, for people to demo and to expose and then, you know, make their tools known and whatever.
Yeah. And obviously you can ask questions of the people working on them. Right. And Peter is the,
uh, Peter Bindles is the host of, uh, tool time this year. Last year it was Phil, I believe.
Oh, okay. And then the other thing is that they are calling for open content sessions.
So open content sessions are things that aren't on the schedule or don't have to be pre-booked.
You can have a birds of a feather talk and kind of just propose it while you're at the conference.
I think there are a couple that are already on the schedule, though.
Right, Jason?
There might be. I was having a hard time telling. It looks like there's a couple over are already on the schedule, though. Right, Jason? There might be.
I was having a hard time telling.
It looks like there's a couple over one of the lunch sessions, at least.
Right.
But yeah, if there's something you wanted to talk about, you could propose it even while you're at the conference, which is pretty cool.
Yeah.
So these are things before the regular session starts, over lunch, after the regular session starts or ends.
And you gave one of these a few years ago, right, Jason?
Yeah, I think the first year that they did it,
I gave one on ChaiScript, which is my...
Actually, I think it was my first year at CBPCon.
Oh, okay.
It was a long time ago.
Yeah.
But yeah, they're open to everyone.
Whether or not you register to the conference,
you can submit one of these and come to one.
Yes.
And then the last thing we have is from Meeting C++, highlighting the student and support
tickets for Meeting C++ 2019.
And yeah, they've been doing a pretty good student and support program.
Looks like they're offering 50 free tickets to Meeting C++ if you're interested in being a student volunteer,
or if you just can't afford to buy a ticket and need some financial support,
or if you're kind of in an underrepresented group,
then you might be able to get a free ticket, which is pretty cool.
And are you speaking there this year, Miro?
No, unfortunately, I didn't get accepted.
Okay, that's much closer to get accepted. Ah, okay.
That's much closer to you than coming to CBP.
Yes.
Tiny bit.
Tiny bit.
Is there a direct route from Munich to Berlin?
Yes, there's a five-hour train ride.
You know, I spend so much time in airplanes.
Whenever I get the chance, I take the train.
I've even done it in the U.S. it's just a lot easier yeah and more comfortable you can get up and walk around
whenever you want to there's not you know food carts going down the thing you don't get the
feeling of claustrophobia that you can get most importantly you get free wi-fi you get a socket
and even if you don't have free Wi-Fi, your 4G probably works
on most of the route anyhow.
Okay, well, Miro, speaking
of CppCon, you will
be there next week.
And your talk is
Non-Conforming C++, The Secrets
the Committee is Hiding from You.
And that talk title definitely
grabbed my attention when I saw it.
Can you tell us a little bit more about the premise of the talk?
Yeah, the clickbait worked.
First of all, I have to say that, you know, you have had committee members on the show before.
So I just have to assume that this show is compromised.
And I have to be very careful about what I say, right?
Okay.
Yeah.
I've already received death threats by the committee
just for announcing my talk
what it's about in general is that
free-thinking C++ programmers in the past
have added features to compilers
that the committee is just hiding from us
they are not willing to put those in the standard
they are classified, you're not supposed to know about them.
Just, yeah.
And I'm going to reveal some of these secrets.
On Wednesday at 15.15 in Summit 8-9.
The revelation will happen there.
Wednesday at 15.15.
I'm not giving a talk on Wednesday.
I might be able to attend.
Yeah, you should.
You should learn about those secrets.
Yeah. Okay. Yeah, you should. You should learn about those secrets. Yeah.
Okay.
Yeah.
So you gave us the clickbait version of the title.
Well, I guess, however we want to flip this around,
but how did you first become exposed to these non-standard extensions to language?
How did you get interested in them?
I mean, I kind of always knew that some existed.
I mean, the first C++ compiler I used was Visual Studio,
and they have extensions all over their place.
I mean, I learned assembly.
It's basically on my tray line from school to home,
and that's how I learned about the decoOspec thing and with the naked, so I
wrote my entire function sometimes
in assembly, back where you could actually
still outperform the compiler. Those
days, I think, are gone now.
But, yeah, so DECOspec did a
lot of things, and then you can create even properties
on the Microsoft compiler with DECOspec.
You can do all kinds of things, so
there's attributes, but then you have
also syntax changes
like unnamed structures
or GCC has things like
statements in expressions
then of course there are things that just were
extensions to C originally
but then were added to C++
or you can use them in C++ at least
like variable length arrays
flexible array members, things like that.
So they extend the syntax and the semantics of the language so that you can do extra things.
So in my talk, I'm going to show a few of them. Some of them are really minor. They're only
quality of life improvements or things that make it less likely
to create
bugs and mistakes. But then
there are also some that appear very
small on the surface, but then when you dig into
it, you realize that they can do things
that standard C++ just doesn't
let you do without dancing
in an undefined behavior minefield.
And the minefield never ends.
So, yeah.
And then I'm going to show one
that has everyone's favorite language keyword,
goto. And with that,
I will demonstrate how you can speed up
certain classes of programs
by up to 20%.
Just sprinkle in a few gotos around.
Yeah, magic gotos.
Not normal gotos.
I had no idea there were magic gotos in the language.
There are.
Well, if you believe the committee, then no, but well.
So, as some of these things, I mean, you mentioned Visual Studio,
and let's be fair, like, non-const referenced temporary.
It's just been a thorn in my side for years from Visual Studio.
On one hand, it's an extension.
On the other hand, I just think of it as a bug.
And where do you draw the line between an extension and a bug?
I mean, I draw the distinction.
I mean, the things I will show have clear intent, right?
They're not something like the const ref.
They're not accidental or something that you say,
well, this could also be a bug.
No, they are deliberate additions to the language
to achieve a certain goal
that you cannot achieve otherwise.
Okay.
I want to interrupt the discussion for just a moment
to bring you a word from our sponsors.
Backtrace is the only cross-platform
crash and exception reporting solution
that automates all the manual work
needed to capture, symbolicate, dedupe, classify, prioritize, and investigate
crashes in one interface. Backtrace customers reduced engineering team time spent on figuring
out what crashed, why, and whether it even matters by half or more. At the time of error,
Backtrace jumps into action, capturing detailed dumps of app environmental state. It then analyzes
process memory and executable code to classify errors
and highlight important signals such as heap corruption, malware, and much more.
Whether you work on Linux, Windows, mobile, or gaming platforms,
Backtrace can take pain out of crash handling.
Check out their new Visual Studio extension for C++ developers.
Companies like Fastly, Amazon, and Comcast use Backtrace to improve software stability.
It's free to try, minutes to set up, with no commitment necessary.
Check them out at backtrace.io.cppcast.
So speaking more on Visual Studio, I know C++ CLI is an extension I'm fairly familiar with,
and that's something that I know is very Windows-focused.
It's so they can talk to the.NET framework.
Are there any other extensions that multiple compilers have similar implementations of extensions?
Or are they pretty much all isolated to a single compiler?
So there aren't a lot that are shared by GCC and Microsoft and Clang.
I think of the ones that I'm going to show, there's only two.
But Clang is trying very hard to be compatible with GCC,
and so is the Intel compiler.
So a lot of the extensions that GCC has are also supported on those.
Okay.
So they're almost driving like a de facto standard
for the expected extensions.
Yeah, pretty much.
There are some quirks, but i think those are just bugs
that you know they're not implementing it fully to the extent that they should like and clang you
sometimes have to put a zero in the array and actually in gcc you don't have to like those
minor things but they behave more or less the same so when you. A non-standard extension to the language that multiple compilers happen to implement,
if they have different behavior, do you submit a bug report to the compiler? Hey,
your non-standard, poorly documented feature doesn't behave the same as GCC's non-standard.
I mean, how does that work?
I guess you can try. I don't know how they're going to react because
these extensions are also pretty old.
So GCC is one I think they're all even from the 90s
or before C++ was standardized.
Oh, wow.
Then a lot of them were written against C99.
So they're not even C++ targeted,
but they are available in C++.
So then you have this question,
how does it interact with the C++ object model and stuff and lifetimes and all of that.
But if one compiler doesn't behave the same as another, then maybe you're just out of luck or you have to convince one of them to change.
Maybe they would agree that it's a bug.
Clang, I think, they are attempting to be feature compatible with GCC, right?
It starts with a command line that's pretty much the same.
Then they have all these extensions.
I mean, someone had to go and implement them
just because GCC has them, right?
So I think that they have a vested interest
in making the code the same
because at some point they also want to compile the Linux kernel
and that's using all kinds of extensions too as far as I know.
So I think it's in their best interest to
match it. And of course Intel, they
probably don't want to screw this up either.
So they want people to use a compiler.
So if I have GCC code that's
using these extensions and they
claim to implement these extensions and then
it doesn't behave the way it does on GCC, then
they probably have an interest
in fixing that.
That's a good point.
That's my take on it.
I don't actually know the answer, but that makes sense to me.
It does make sense, yeah.
They are, I mean, like you pointed out,
both Intel and Kling are trying to be drop-in replacements for GCC.
They want to convince you to use their product,
and that's the best way to do it.
Correct, yeah.
And one of those companies asks you for money so right they have an even stronger interest yeah yes uh you mentioned
that a lot of these extensions or some of them you know predate the standardization of the language
are there less extensions being made now that c++ is being iterated on on a much more rapid clip?
I don't think so. Like, I think that with the increased conformance hypes in C++11,
I don't think that there is a lot of effort being put into creating extensions that aren't already
on the path to becoming a feature in the standard. That makes sense. Yeah, I mean, if you look at all the compiles, right,
Microsoft rewrote the entire frontend to be
compatible with C++11.
Well, 98 too, I guess, technically.
But, you know, there's a lot of effort being
put into conformance.
And, yeah, in the past
years, the only extensions that I've seen
are the ones written by proposal
authors to
have a proof of concept for their papers.
Before it's standardized, yeah.
Microsoft also made a library
to replace one of their extensions.
Which one? I don't know.
The C++, yeah,
except we had Kenny Caron talking about that.
To replace the CLI, basically.
Not CLI, but CX for the more modern Windows, yeah.
I cannot keep track of them.
I've never used any of them, the CLI, CX, or Kenny's library.
I did use CLI, but I never used CX.
A lot of people.
Only a few people have, probably.
So, I mean, one thing you mentioned a couple times now is a magic go-to and if you want to you can
just leave that hanging so people come to your talk but i am curious particularly with something
like a magic go-to are you willing to put this into production code if it was my own product
and i could very clearly measure the difference, then probably.
But I don't think I would put it in an open source library or something without some compiler if devs around it.
Because it is still an extension and people are assuming
that the code you write is standard conforming.
But in that case, I would probably provide a switch and say,
hey, if you're using a compiler that has the support for this
and you care about the performance of this particular part, you can put on this switch
and use this extension. And I mean, which software engineer wouldn't say yes to a 13% speedup?
Well, yeah, I mean, if you could really document that, that would be...
Yeah.
So in general, do you find that many of these extensions that you're going to talk about are things that can be isolated, switched off, whatever?
They're not going to become a fundamental nature part of how you wrote the program?
No, I think the magical goto has, that is something you would use for a very specific
use case.
Okay.
Then the other extension is also for a very particular use case, but it is,
well, yeah, there's a bit more to that, but it's useful. But yeah, you can isolate these things.
You can make it just in one function or in one class. Okay. Though the thing I mentioned about
undefined behavior minefields, you know, they come back when you switch off the extension.
And one of the features I will present, I am convinced that you cannot implement the same thing
as efficiently in standard C++.
And I will show the way, the path from the start of implementation
all the way to the end where I give up.
I would make an interesting challenge if you leave your talk saying,
this is the code sample.
I do not believe it is possible to do it as efficiently
and see if anyone comes back in a couple of weeks or whatever.
Yeah.
I mean, I gave this talk to my local meetup,
and they already found more undefined behavior in my slides
than I knew about.
So it's like, it never ends.
Undefined behavior, one after the other.
You think you fixed one, but you created two new.
And this is the version that doesn't use
the magic go-to?
Yeah.
This isn't about the go-to. This one is a different
feature.
The magic go-to, that's just
making something that already works faster.
But the other thing that's
making something possible,
it is impossible right now,
I believe.
Are you going to tell us a little bit more about what that other feature is? that's making something possible that it is impossible right now, I believe. Huh.
Are you going to tell us a little bit more
about what that other feature is?
Well, flexible array members.
Do you know what that is?
I don't think so.
No.
Well, then come to my talk.
Don't look it up.
Don't cheat.
Don't cheat?
No, I won't cheat.
I won't cheat.
The closest I'm aware of is uh
the dynamically sized arrays from c99 stack arrays with a runtime integer around right yeah
yeah runtime sized although i just read a comment saying that those are like
that it seems to be that people agreed that it was a bad idea, and they don't actually get used a lot in C
because they end up with undefined behavior and stuff happening in them,
but I don't know anything about it.
Yeah, I mean, I actually...
Sorry, I interrupted.
No, sorry, go ahead.
So that was one of the features I actually wanted to present,
but then I just ran some benchmark on Compiler Explorer and stuff, and if you just use
a boost static vector, it's generating the exactly same code, and you don't run into this problem of
blowing your stack unless you put a very, very big constant on that container.
Well, there you go, then. So we already kind of mentioned that some of these extensions might be
things that are being worked on for the committees, right?
I mean, like just hypothetically, like concepts implemented as an extension to GCC years and years ago, right?
Are any of the things that you've come across or that you're talking about are things that were at one time considered as extensions?
Or maybe perhaps things that you think will become later into the language, perhaps?
I mean, not extensions, but superficial.
I don't think so.
Okay.
But it's also difficult to find out
because a lot of the things
on the internal committee reflectors,
I mean, some of them were added to C,
so one then might ask, you know,
why not in C++ too?
Right.
But I'm not actually sure.
It's also a bit difficult to find the history of these extensions
because they go so far back.
I still, okay, at some point after this talk,
I'm expecting you to submit a proposal to the committee
to standardize the magic go-to,
because we need more go-tos in our code.
This
magic go-to is also one very, very
magical aspect, and that is
foot guns are pretty much toys
compared to this.
You can
go, you can supernova the solar
system if you screw up with this.
Okay.
So it's possible to avoid...
Oh, sorry, Rob.
I was just going to say,
it's probably not going to be standardized then.
Probably not.
Well, you never know.
I mean, if you count the amount of undefined behavior
we have already, I mean, what's one more, right?
Yeah.
Sure.
So you are talking about things
that don't have to involve undefined behavior
and can have a real
significant impact in your project. Yes. Sounds interesting. I mean, right, the undefined behavior
comes from the fact that the compiler knows what you're trying to do. Except in the other case,
where you're just trying to do some random pointer arithmetics, and then you realize that the abstract
machine doesn't like that. That's like, yeah, that's where a lot of the undefined behavior comes from,
that people are just,
they think they're programming the CPU,
they think they understand how their hardware works,
but in reality,
you are writing instructions
for the abstract machine of C++,
and the compiler reads your code
as instructions for the abstract machine.
And then things that you think should make sense
and should work just don't,
because the compiler is a barrier in front of the hardware.
And that's why one of these extensions was created just for this one purpose,
because even in C, you have these object models and abstract machine that you have to cope with.
I don't think I realized that in C, you also were technically programming the abstract machine.
I never stopped to think about it.
Yeah, and C also has lifetime and object models.
And they're different to C++, which makes it very...
You think you can just include a C header and it just works,
but it might be full of undefined behavior
because you're including a source file of a different language
that has different rules.
And this is why I always advocate that our C++ header file should be HPP instead of.h,
so that we know what language we are actually working with.
I fully agree with that.
All my files are CPP and HPP.
You're only one of, like, five people that I've ever talked to that fully agree with me on that.
But I push for it.
Yeah.
Just for the record.'m sorry i keep interrupting
you no no i was done sorry uh the the c++ core guidelines for anyone who cares actually
specifically say to use dot h for header file extensions because it is the de facto industry
standard or something like that and i fully disagree with that i'm with you on that too
yeah now we just have to sort out which side we put const on and we'll all be on the same page
um so in your bio you said you currently work as a freelancer and trainer uh when you're doing
some training are you trying to encourage the use of some of these extensions or are you keeping it to conformancy plus plus?
I stick to the conformant part, yeah.
Now, I know how training goes, though.
Every now and then, your students ask you a question
and you have to be like,
okay, well, technically you could use this extension, right?
Like, it has to come up every now and then.
Yes, the word technically is one of those words that
when you use it, then people already know
aha, aha, so there's a
but. Yeah.
I semi-regularly
will have students say something,
oh, so that's impossible in C++?
And I have to go, no.
It's C++. Nothing is impossible.
If you have a compiler that doesn't turn all undefined behavior into mush.
Even removing undefined behavior, there's probably some way to do whatever they were asking for.
But if you allow undefined behavior, oh yes, yes.
Let's go ahead and rewrite the V table so that we're calling different functions.
I mean, it's technically possible to do these things.
And the compiler is technically allowed to just punch you in the face when you do it.
Right.
So on the topic of the compiler punching you in the face,
I am a big fan of using WPedantic warnings,
which I'm guessing if you're using these non-conformant extensions, WPedantic,
I mean, that's the specific reason that warning exists, right?
It's to tell you you're doing something that's non-standard.
I mean, for many of these things, you don't even need them.
Clang flags them automatically.
It says that it's on C99 extension.
Okay.
So for many of these, you don't need any extra flags to find them.
Now, you already said that if this were like a publicly visible product,
you wouldn't do this.
But if it was like some private project you're working on, or whatever, and you said, I'm going to flip on this 30% savings here, would you put pragmas around that code so that it doesn't generate a warning with W pedantic? Or would you leave that noise there so that people who are compiling in that mode are like, Oh, okay, yeah, um this this code is off in a gray area already that's a good question i mean if i was alone i would turn it off because it's
noise and i want to see the real warnings that i care about which is everything minus a blacklist
but um all the warnings except for the ones you don't care about yeah uh but otherwise i would Yeah. But otherwise, I would probably put this pragma around some preprocessor stuff
so that it doesn't fire on compilers I know support this
and then maybe have an alternate implementation if that's possible
that's conforming.
So, yeah, for example, using the Microsoft compiler,
which doesn't have this magic go-to,
but then you could also just, for example, for this one file, you could use Clang CL.
And then it's going to generate an object file that's compatible with all the Microsoft-generated stuff.
And then you can use the Microsoft toolchain for everything else.
So that's something you could do if for some reason you have to use the Microsoft toolchain.
For my own project that isn't public
or that I don't intend to give support to,
even if it is on GitHub,
I would probably use it
if it's worth the savings that I get from it.
Okay.
I'm sorry, but when you said,
oh, I could just compile that one file
with Clang CL on Windows,
I don't think I've ever heard anyone advocate, oh, well, I'm just going to pick and choose
a couple of files here.
I'll compile with one compiler.
Technically, it should be fine.
They're ABI compatible, using the same standard library implementation, whatever.
But it sounds risky to me.
It probably is risky, yeah.
Okay.
But on the other hand, the LLVM folks try to be as compatible with the Microsoft compiler as possible,
so you can use it as a drop-in replacement.
And you can still use the standard Microsoft linker for everything.
You don't have to use LTE.
So the object format that is spit out of this is the same,
but then, of course, all the macros and all the sizes and alignments and
layouts and stuff you better hope it's the same too be fascinating if they did some sort of like
fuzzing project where they would choose a random selection of files in a project to compile with
each compiler and then see if all the tests still pass and then try again with a different random selection. That's a good idea.
Maybe they should do that.
Compiler fuzzing.
Did we break the ABI today?
Right.
Do we have anything else to go over?
Is there anything else you want to talk about, Miro?
I mean, only the standard is a lie.
Don't trust the committee.
And come to my talk.
Okay.
Okay.
Well, it's been great having you on the show today.
Thank you for inviting me.
Thanks for coming on.
My pleasure.
Thanks so much for listening in as we chat about C++.
We'd love to hear what you think of the podcast.
Please let us know if we're discussing the stuff you're interested in.
Or if you have a suggestion for a topic, we'd love to hear what you think of the podcast. Please let us know if we're discussing the stuff you're interested in, or if you have a suggestion for a topic, we'd love to hear about that too.
You can email all your thoughts to feedback at cppcast.com.
We'd also appreciate if you can like CppCast on Facebook and follow CppCast on Twitter.
You can also follow me at Rob W. Irving and Jason at Lefticus on Twitter.
We'd also like to thank all our patrons who help support the show through Patreon.
If you'd like to support us on Patreon, you can do so at patreon.com slash cppcast.
And of course, you can find all that info and the show notes on the podcast website at cppcast.com.
Theme music for this episode was provided by podcastthemes.com.