 So thank you everybody for coming I'm quite impressed this talk has gathered such a crowd on an afternoon after lunch of the last day so I hope I won't be too boring with you I understand you've had you've just had lunch maybe I hope that you had coffee to keep yourselves awake like I said I'm quite impressed the number of people who have showed up I remember pitching this talk to a colleague of mine at Intel and he's a kernel developer Linux kernel develops and no I'm not gonna accept you I don't want to see anything about C++ I even spoke to Linus once about C++ and I don't know if you've ever talked to Linus about C++ he's got quite an opinion about it so some of the things I'm gonna show are my phone just put it here my so nobody ever calls me I never receive any text and apparently this is the first time that happens I was saying Linus has quite an opinion of C++ he considers many of the things I'm gonna show as misfeatures I consider them as features so let me briefly introduce myself I'm Tiago Maciera that is me working with high technology back in 1982 I've been involved with open source development for well over 15 years I'm gonna say exactly how much most of that time has been actually working with C++ so if any of you were on my talk yesterday when I was talking about IPv6 I started my career in open source by working with IPv6 I was asked what do you want to work on I decided I want to make a browser capable of IPv6 and Mozilla at the time already had support for IPv6 I started with the KDE's browser and if you're familiar with KDE you know it's written in C++ so that's how I actually ended up working with C++ before then I had access I had submitted a patch to Linus Kernel I had made a couple of modifications working with Pascal with Clipper but it wasn't until I started actually doing C++ that I got into my professional career and both C++ and IPv6 actually landed my first job in open source when I went to work for Chaltec and now I work for Intel as a consequence as evolution of whatever I was doing back then so my job today is to say and convince you that C++ for embedded is possible and it's even a good idea let's quickly let me just take a quick survey of the audience here how many of you program for embedded systems okay I should have asked the other way around and since we're in embedded Linus conference that was to be expected quite dumb of me how many of you do that with C++ you guys can leave I will be reinforcing that idea to you and hopefully I will be giving you more arguments whenever you come to a colleague or a product manager or somebody else who says no no no C++ is too big is isn't there work for embedded for those of you who don't what's your main language of development see right anybody working with PHP okay one yeah so the interesting thing is that I'm working with IOT these days and I see a lot of people doing Node.js or JavaScript I had a colleague presenting earlier this morning about using JavaScript with Node.js style API to program a microcontroller so working on Zephyr I'm not gonna pass judgment I think that if we follow the engineer's motto here which is the right tool for the right job what I'm trying to show you is C++ is a good tool and we'll do a good job so I divided my presentation into three sections first I'm gonna convince you that C++ is not bad that it actually does work for what we want to do in embedded then I'm gonna show some reasons why it's actually better than the competition that we see and then I want to finish with some of the things that are exclusive to C++ I don't have slides for all the things I'm gonna say at the end I'm just gonna start rambling about some of the things we started to think about in C++ and I'm here to help it to answer questions so feel free to raise your hand if you do not understand me I understand most of you are not native English speakers neither am I so feel free to stop me and ask me something so as I said the question we are trying to answer is which is the best language for embedded programming I already gave you a hint of what the answer is and it I'm not gonna say it C++ the best language is the language you're most comfortable with I want you to do a good job in developing systems and especially when we're talking about embedded programming and we're talking now about the embedded programming connected to the internet also known as IoT you need to be doing a good job these devices need to be updated need to be securely written and need to do their jobs without blowing up every five days because they just use too much memory so the correct answer is use the language that most you know most that you are most comfortable with and serves your job so PHP might not work on an embedded system maybe Java won't work because it is the VM takes too much and garbage collection is not gonna help you but one that might is go so you see the little gopher on the top there it is actually a compiled language right I don't know too much about it but I keep hearing from colleagues who do that this is an awesome language and more than that we're here at the embedded Linux conference go because of the way it is developed enforces basically that everything has to be open source but anyway I digress Python and Ruby are good options as well even though they are interpreted languages they can be byte compiled they have a garbage collection which may not work for everybody the normal options for we have our CNC plus plus again that's what I'm gonna be looking into let's start with a couple of facts or myths C plus plus is more complex than see facts or myth it's a fact so it's actually a fact because yes the standard is bigger I'm gonna take a parenthesis here and talk about what the languages are so both C and C plus plus are developed as part of the international standards group ISO but organization ISO they are both standards in that organization and if you want to read the specification you usually go to your national body and you download you buy the specification comes in a book they are quite big this text is very dense it's meant to describe an abstract virtual machine that would redo something point is the C plus plus standard is longer and it is complex because it does more stuff that doesn't mean the language is more difficult another one C plus plus language generates more code and or requires more RAM myth that is that indeed a myth it does the language is designed around you don't pay for what you don't use right and even some of the language features can be turned off with certain compiler switches so we're gonna talk about exceptions later for the moment if you just want to not pay for the cost of exceptions your writing code that doesn't use exceptions there's a switch that you can pass to your compiler will turn them off and you don't pay for the cost of it so which options those are so if you're not using exceptions for example GCC you're gonna use f no exceptions and this other option that I actually hadn't thought of until I was actually writing the code to figure out the difference in size the asynchronous unwind tables and that's interesting because that applies to C as well I was trying to compare the size of a buy of a certain function you're gonna see later in the presentation between using exceptions and using manual error error detection and error handling in C and it turns out that the C compiler GCC was producing the equivalent information for unwind that is how do you throw an exception through that function which would have meant that if you did that C code would be unsafe because it did not properly handle the case of the exception going through the propagation so if you want to use C++ without exceptions those two options if you in addition to not using exceptions you're neither using type ID or dynamic casting there's an extra option you can use called f no RTTI which stands for runtime type information that turns off the runtime type information most of the time if you're writing compact C++ code you're not gonna you're gonna see any difference that one appears when you are besides these two operators when you have polymorphic classes with virtual functions so the moment that you have a virtual function the compiler will emit the runtime type information for that particular class so you can save a couple of bytes by not having it it's gonna be about 20 30 bytes per class and if you're not using the standard library and that's gonna be a big problem for us to discuss you can actually disable the use of the standard library now you can turn completely off because the compiler will still do a couple of things that are required so some of the things that the GCC and G++ and Clang do and any other GCC plus plus compiler do is they call out to a couple of methods or you use a couple of symbols from the C++ language support right both GCC and Clang's libraries I'm gonna see later have sub libraries that contains those symbols so you can use only those and if you install on a regular and this is in distribution those actually come as a static library so you can easily compile a C++ application that uses nothing more than the C library another myth would be the the C++ language hides things from the compiler and I realized that I did not hide everything in my slide so you know this is supposed to be what the hell is the rest of that was not supposed to happen so this is what happens when you don't so you I reviewed all my slides but I never ran them through in presentation mode so the animations I never looked into them so it's a myth you you can hide stuff yes but no more than you can do with macros in C in fact I would way I would say that the extensiveness of macros because you can't do many things in C so because there are certain things you cannot do in C that you can C++ the use of macros in C++ is smaller in term that means the the converse means that you're using macros a lot more in C and that has sometimes a very very unexpected effect so my rule of thumb whenever you and this is for you if you're compiling code and you see a narrow from the compiler that makes absolutely no sense because it has nothing to do with the code that you're looking at look at the preprocessor output it's very often that somebody defined a macro to one of the words that you use in that line and then the compiler thinks that where you wrote interface and this happens often I have a lot of code in D bus that uses the word interface that that word should not appear there it's not a valid variable name of course not because windows.h defines it to be struct so you cannot define something like that so be careful we had cases of maybe give you another example you're writing an application that defines int sun and moon can anybody tell me which operating system that will not compile on I'm gonna give you a hint one of the companies is named after that so no didn't longer exist independently but on Solaris made by Sun Microsystems Sun is defined to one trust me when I compile the code was a same example 10 years ago like why doesn't this call I compile on everybody else and then it didn't compile on the Solaris compiler starts to blame the compiler until I figure that one out so anyway I digress the next question and let's see if the animation works using templates is more expensive so I'm the answer here I'm gonna hedge my bets and I get an animation didn't work it's yes and no so templates by themselves do not imply that you're using more code or more RAM that's a myth it does use more increases the compilation time because the compiler has to do more things and thus uses increases the memory use a job of the compiler but by itself they do not cause more code or more RAM to be used however because of the way people currently use templates and the fact that we're trying to produce more optimal code by eliminating function calls eliminating out of line all of this ends up as inline code it does end up increasing the code size it's not a requirement for templates for that to happen but it does happen the way that templates are usually used so both yes and no and the last one and animations again I'm just gonna skip the animation so C plus plus compilers are not as good as C compilers that's a myth so if you're using any of the major C compilers today they are C plus plus compilers are equivalently good so both client GCC Microsoft Visual Studio compiler the one from Intel the company I work on they are just as good in C and C plus plus in Microsoft's case the C plus plus part is even better because they do follow the C plus plus standard they do not follow the C standard so for example they only brought C 99 support to their compiler when C plus plus started requiring it however they're not as widely supported on embedded platform that's why I'm here so for example I was talking to Anna's Nashiv from the lead architect in in Zephyr and said yeah we don't support C plus plus nobody has wanted it to do it but if you want to give it a try take a look and I'll probably be doing that just as I mentioned compilers and standard and this will give you a picture of what I said before about the libraries so on as a regular Linux system you're going to see either of these two compilers GCC or Clang they're more or less equivalently good in jaco generation in micro benchmarking I can tell you GCC still generates better code than Clang whether that's going to remain for long or not we don't know GCC also does have a couple more aggressive optimizations so we had a problem in Qt recently related to the dead store elimination I will not get into the details of it it's just a new switch they added into GCC six and we could not see what was wrong in our code it took somewhat while to identify that yes we were violating some of the requirements of the C plus plus language and therefore the compiler was right to eliminate some of the code that we did so both Clang and GCC are equivalently good GCC comes with its own standard C plus plus library and they're not very imaginative with the name it's called lib standard C plus plus Clang because lib standard C plus plus was taken just called the lib C plus plus it's an LLVM library the main difference you're going to see in these two is the license so the GCC one like GCC itself is licensed GPL version 3 with the runtime exception whereas the LLVM code is more often licensed BSD so on many of embedded systems because of the provisions of the GPL for example you might prefer to use a BSD I'm not a lawyer so this is not a legal recommendation it's something that you and your legal team need to come in look into Clang has been designed to work with both libraries so it actually does work with both just fine and I've seen many Linux distributions that default clang to use lib C plus plus and my answer is don't do that don't try to make that choice on behalf of the user if the user wants to there's a switch that you can pass to the client command line that will switch it from one to the other but you should default to using what everybody else is using on your system which is lib C standard C plus plus in theory GCC should work with lib C plus plus I have actually never tested it it's something that I should should be looking into soon because of the what I said about Zephyr inside those two libraries like I said they're sub libraries that support the language itself and do not provide the rest of the standard library definition and those would be libs support C plus plus and lib C plus plus ABI if you take for example on Mac OS what Apple has done is that most of the applications today are linked to lib C plus plus and what they've done is that they've replaced lib C loops lib sub C plus plus they taken it out and they've made lib C plus plus ABI a separate shared object so both libraries link to the same same core as a result you can actually run and blowed run applications that link to both libraries at the same time they're compatible among themselves now you can't actually pass structures that you find in one to the other so for example standard string you're not going to be able to pass across the two libraries but exceptions are going to work you're going to be able to call new on one and delete on the other and that just works just fine and that's also because all of this ABI has been defined previous it was actually defined during the itanium processor apparently some people at Intel had too much time on their hands and they decided to do a C plus plus ABI that was published today it's still known as the IA64 C plus plus ABI but it applies to almost all of the processors you see today they depend the made the normal libraries depend on lib C so if you're going to look at embedded systems you're going to have to choose your lib C if you're going to microcontroller systems that gets interesting because you don't have a lib C with a C API and a posix API and more importantly you don't have a P thread one so many of the things that exist in the current standard C plus plus 11 14 17 you might not be able to use on very tiny embedded systems but if you're looking at Linux this is just how it works any questions so far okay so let's look into why I think C plus plus is good let's start with something that bit me when I was working on so I'm the maintainer of a C library called tiny seabor it's meant to run on Zephyr I wrote in C because well I just didn't want to have the fight back then so I just wrote it in C it was that simple anyway and just as I was starting with the project I had not configured my compiler with any special switches the following code like this compiles and you can see that in C it prints a warning it doesn't cause an error and C plus plus is an error and if you're compiling like you you just starting you compile the seek this file over there and then working on something else you never realized that this went through with just a warning why is that bad let's suppose that G is a function that takes in 64 this function here past a 32-bit parameter so G did not take a minus one it took you into max so I've seen many code bases in C where they actually have a couple of W error so they turn a few warnings into error missing prototypes is one of them right so if you're working in C you probably want to make W error equals implicit function declaration never allow your C code to compile like this in C plus plus it's not required because it is sorry it's not required to make this an error because it is already an error the language requires that it is that it be defined before there's another reason for that it's because C++ supports overloads so it needs to know which of these functions to call the ability to call without a prototype is legacy in C it actually is inherited from B the language that came before C so if you didn't know your history yes before C came be in B you only declared you did not declare parameters so that's why in C you just have the parenthesis you never have anything inside everything was simply word sized so that would have worked here they didn't have the problem 64 bit but that said we say yeah that's that's just legacy from B this one I find inexcusable so in C casting across different pointer types only triggers a warning like in C++ that's an error so the example here is what happens if I pass a short pointer to an int pointer in a function the C compiler warns but does not stop so this is another one that you might want if you're using C to make an error of in C++ it's an error I simply cannot tell you why this in C is not an error I just can't think of any reason why anybody would want to implicitly cast from a short pointer to int pointer this the one below is the dropping of const that one has more of a reason because the original C language did not have const so it's a bolted on keyword it appeared shortly before C++ was invented of C++ actually came with with const yeah I mean at least is the right type but if I drop the const I might be writing to memory I shouldn't be writing and if this is pointing to read only memory my application will crash so these are really weird for me working from C plus from C++ to accept that they are correct in C in other in it putting it the other way around if you program in in C++ your code is safer because you will not commit to these errors the compiler will simply not let you the next one according to Linus is a feature void pointers so you are allowed in C to cast from void into any other pointer without a cast the common the most common use of this is in short car pointer something equals maloc you do this very often in C now what happens is that maloc returns void pointer which gets automatically cast to car pointer in C++ that is not allowed and here's why so I have now instead of two I have three functions if you look at the bottom most one it's the short pointer again so I'm calling from F I'm calling G and that is okay it casts to void so my short pointer gets to void star but the G function takes that void void star and casts to int star without checking so I can't stop you from casting casting has a place it has a use but let's be sure that you do the right thing in C++ this would have been caught and would have made you think oh which one was this supposed to be do I really by the way do I really want to do a void star API you if you can't don't you would use templates here but in C++ it is a narrow and see it's neither narrow not even a warning so since we talked about casting I'm just gonna plug in this trick to type safety introduces the cast operators here for no other reason that they're easier to grab for so if you need to figure out if you're doing anything wrong if you need to do an audit of your code to make sure that you're casting right things to the right things right you do a grab for static cast all of these it's much easier to find these words which cannot be used in variable names they cannot be pre-purposed than to find to write a regular expression that does casting of types in C I would actually say it's impossible to write one the other advantage of having them is that you can't accidentally do more than what you intended so if you're using const cast the only thing you can do is drop the CV qualifiers CV qualifiers const and volatile yes but if you're doing a static cast you're not allowed to drop the const so you can do a couple of things with static cast but not cross barriers that unrelated types and you cannot drop the const cast so yes and sometimes you see longer code in C that does a const cast to something intermediate and then does static cast to the destination yes it's long-winded but I'm explicitly saying what I'm trying to do I cannot by mistake lose the const I had the code base in in cute that was using old-style casts and where C++ we call C cast old-style casts that's actually the the GCC warning for it is W old cast if you do that you try to compile I was trying to remove them it turns out that the code base because it was it had been refactored so many times along the way it simply could not be done it simply could not get const safety everywhere and get rid of those annoying C casts some functions were supposed to modify called functions that weren't and then called back into things that were anyway from the beginning use them the next topic is just organize your code into classes so I searched for this is gglib code you can see it's actually from gio it's a gd bus function I was just searching for an example of something short that called a couple of functions inside as you can see this code I hope that everybody in the back and see it by the way the presentation will be available online later so you can look into the code what it does is that it does string new which allocates something I have no idea why it needs a null that's my opinion on cp and on a B API design why does it need a null there then calls string append string append C while it's a string why do I need to repeat myself that it is a string so the equivalent code that I just wrote for this with with the cute classes with cubite array it just calls append now if you're paying attention there are two things different in the C++ code from the C one is more or less evident something's missing on the C plus plus code the free we're gonna get that into later the other one is not as evident and this is something that people actually do complain in C++ because they're saying you're hiding stuff can anybody see what is different between the two what I could be hiding so the answer is look at the third append right it is equivalent to an append C I actually looked into the what what this was supposed to be in in in Jolib it's happening a simple character right so it is the same append function and the reason for that is that we're using overloads in C++ in my opinion it which is not shared by many of the C code is it is actually better to have the overloads here because they do the right thing and I don't have to worry which of these functions are it behaves the same way so if I were to change my arguments I wouldn't have to change the function in fact if this were a Q string instead of cubite array the code probably would compile anyway and just do the right thing with a Q string instead of a cubite array even though it doesn't operate on characters but on Q car which are unit code right so since we're talking about overloads unimproved functionality in C++ are overloads so I just copy this from both the C and the C++ standards on the right you can see the C standard from section 712 7 2 so all of chapter 7 in the C standard is the library on the C++ standard since the library so much bigger it is many many chapters chapter 26 if I'm not mistaken is the numeric support yeah so it's just showing what we can do with overloads on the right side we have f abs so floating point absolutes and you have to call f abs f if I want a float based floating point absolute in C++ you have f abs float f abs double and f abs long double you might say well why do I care I'll just call f abs on C why does it matter that it did I have an overload have you ever done floating point emulated in CPU many of you have and working with doubles is more expensive so if I can operate on maybe not this case of f abs that's actually an easy one just flip one bit but on many operations of using float speeds up the code base so you want to use if your code is only floats you want to keep with floats you don't want to accidentally use double and increase your your runtime because you have to do more precision in C++ we have just call f abs it will call the right one and it even has an abs one which works as integers that allows us to do generic programming now if you ask me when I'm working with C the thing that I miss the most the one thing I would give my castle for if I could just use in C are exactly destructors so I copied this from the front here slightly smaller I was just searching the Linux kernel because glib does not do memory it does not check that Maloc succeeded not not going to that so I'll search into the kernel of an example of Maloc failing came a lock failing and it actually did a couple more things after that right so it's not actually easy so that's a good plus for the kernel they try to avoid doing complex things in functions to avoid exactly this particular problem I know one particular function that is much worse than this it is the one that is called whenever new process starts it needs to locate a ton of different things so it has a at least 10 different go to this is a simple one it has to go to so if you're programming in C very often you will write code like this go to isn't so bad after all and I'm not passing judgment go to actually serve as a purpose that one is pretty good so what you see here is you do a camelock and if it failed I'm going to return you know ma'am I could have just written here they just use the same one below it does amount mutex lock a spin lock does some work inside and in the middle of a get a loop that happens inside the path variable might be initialized to false which indicates to know which indicates a problem and in that case it needs to return on their name too long and if that's the case I need to unlock what I had locked and free the memory the working buffer so you have to pair the code like this and if you have more things that might fail in between you have to do more of these so the thing I missed the most in C is resource acquisition is initialization somebody said right that's the full expansion so I invented here some function so I a class called pointer holder specifically for the kernel that would do the same thing and then look at I'd actually have mutex locker not mutex lock and spin locker not spin lock so I created two extra variables on the stack here automatic variables and as you can see from the rest of the modification that I've done I don't need to remember to unlock them I don't need to remember to free the buffer why is that because the destructors will run right and the destructors will do it for me which could be called hiding it is definitely handy because I don't see it here but in could be code bases where you use right resource acquisition is initialization properly and only it it's actually produces safer code so ever since C++ 11 and more so with C++ 14 there's a trend to get people to stop using raw pointers there are enough in the C++ standard library there are enough classes in the C++ standard library to hold them and manage them for you specifically unique pointer and share pointer that you almost never need to deal with them directly that means that you you can still leak if you try hard enough but it makes it more difficult the biggest problem you have to face with shared pointers are cyclic reference counting loops so when a depends on bb depends on cc depends on a you might drop all the reference but since they all have a reference to each other they never get destroyed on garbage collection systems the garbage collector actually has to have enough intelligence to do a pass and verify that came back to the original one without increasing the use count and then all of these can actually be thrown away same problem exists and if you're using reference counting so yeah so you're right some people in C will complain that the closing bracket produces a lot of code yes it does right and the worst one is when you get a compiler error in the opening bracket of your class that's another issue yes I've been hiding code right but the interesting thing is this actually made it more it made it safer I've got a colleague who's a really good C code he doesn't like c++ at all there's a feature an extension in GCC that tells it whenever this variable goes out go out of goes out of scope call this function so you can actually implement destructor like functionality with GCC it's not part of the C standard but GCC allows you to do this so he actually started using this in his own code base because yes it makes it it makes it safer so I'm willing to sacrifice some verbosity some explicitness that's not called a verbosity for the safer code we're gonna come back to this again later when we do exceptions in a couple of slides I didn't know exactly what to talk about the containers I was struggling with what to write in this slide so the c++ standard library has a lot of containers it is in my opinion the single most important thing that the c++ standard library has ios streams throw them in the garbage the containers are good and more important than that those containers in both Libc++ and in Libc++ are written by the same people who wrote your compiler they know how the compiler works that means hopefully that the container is the most optimized possible that could exist for that particular compiler and it often is it's very hard for you to write something that is as generic and as efficient as the c++ standard compiler standard containers now you can write specific specialized code that is more efficient yes definitely but to make it generic to work with everything it's a little difficult the example I wanted to give and we can draw it later after the session is the normal uses of containers so in in a c codebase what kind of container is the most often used a linked list linked lists so I was grabbing the glib source code and I found they have g array which is an array and I started to figure out where is this used almost nowhere they don't use it on their own codebase glist however which is a linked list they use it very often in the c++ world the structure the container that is most often used some vector which is an array and I can prove to you that a vector of the same number of elements of the same size is more efficient in many factors so it's faster to search it's faster to iterate over it has less memory overhead so I mean by meaning fewer malox it uses fewer cache lines and because it's sequential it actually helps the CPU can help you because it knows you're going to usually progress sequentially if you're iterating over a linked list you might be through going all over the place in memory so the cache lines on the CPU cannot help you by prefetching information that you're going to need a couple of instructions down the line right the problem with them two problems actually one is they're not optimized for code size most often c++ library optimized for performance this is why a lot of these things are in line so yes it's going to produce the fastest possible by the by having as a counterpart putting all the code exactly where you used it so it's not calling outside whereas often when we're doing embedded programming we want to actually have shorter code to fit whatever memory we need so the question is if when I mean optimized I mean before or after c++ 11 build both but more so now with c++ 11 move semantics and and more so they are optimized and the reason again is because all of this ends up in line though code is all generic and ends up in line the compilers today both GCN Clang are not as smart enough to do code analysis after code generation and identify that these blocks of code are actually identical they do it before usually before they expand to assembly and they don't realize that it's actually the same after expanding to assembly so there's room for improving this more especially if you want to do optimization for size just remember one thing parentheses GCC optimizes for size a lot better than clang does so if you're doing compilation with OS you want GCC not clang today I said there are two problems the other problem that I personally have with the standard containers is that the error reporting they have the only error report they have is exceptions so there has been discussion there have been discussions on the the c++ committee and standard mailing lists should we have non-exceptional code should we support this the people there came to a compromise the answer is like this we believe we meaning c++ standard committee that exceptions are the answer we should be using exceptions and therefore we're going to design our containers and our API around exceptions that said we're going to make it easy for people who don't want to use exceptions to still use some functionality so as an example the upcoming file system API in the c++ standard is expected to have as return values standard expected so it's a container that contains that has a parameter a template parameter is your return type might but it might be actually disengaged containing no value but instead containing on error code that allows you to query it are you an error condition and handle it normally or if you don't and just try to access the value it throws the exception at that point so it is the compromise we've found so the people who push and say exceptions are good their argument is yes it looks like it increases code size it looks like it increases code size but that's because we're actually handling all possible errors and not missing anything so I did a test I've gone let's go back to that C group function inside the C the kernel code so I just rewrote it now to use I have the actual complete code for this so the dot dot dot in the middle is I have it I spend some time just drink dummy of everything that called and all these these functions around I just wanted to know the impact of switching from C with the explicit error checking and go to use to using exceptions so there are basically two points in this function where an exception can be thrown the first of them is this came a lock right so I didn't change I made I made it so came a lock is not marked no except so it might throw I wrote the actual pointer holder for a class and the function in between that actually you can't see here because he wouldn't be able to read it the function that would have returned the null path I made it a throw or since it's it's all known in line that basically did not mark it as no except everything else all the other functions especially the ones in the kernel that returned void I simply mark them as no except which means that the source the compiler is looking at it say I have two points possible where it's possibly going to throw one of them is before anything happens it's actually the beginning of the function that this came a lock here so it might just throw and doesn't have to do anything or in between in that dot dot dot there in which case he needs to destroy three objects the two lockers and the pointer holder note that I don't have to return you know man because that's actually an exception from I actually also removed the code that did return ename too long because that's supposedly now an exception so if the function inside said well I can't fit the the name that you wanted me to in the buffer that you passed me I'm gonna throw ename too long right so the only return point in this function the normal return is this return zero at the end this it actually means this function did not need to return in it could just have been void because it always succeeds or throws I actually just realized this when talking to you I could have made this void I compiled it and as an exercise I use the ABI the ABI for the Zephyr operating system which I believe is also what the kernel uses inside itself it uses basically passing by your registers as a result the code size grew 16 bytes and it added the exception table that wasn't needed before and this is where I found that the F no asynchronous unwind tables was important in C as well because when I had just compiled it in C and had not noticed it it or it did it emit an unwind exception table for C so the difference between the C unwind table that was there and the C++ unwind table with exceptions was 16 bytes only so 0 10 x right 0 x 1 0 the other thing that changed and this is actually where these 16 bytes come from is that the error handling was removed from the main code path really so I'm gonna leave you with that I had like I said a couple of more C++ is awesome I'm just gonna quickly go through them lambdas I love lambdas it's a good thing to use they can be used in C as well as this example shows the range for I'm gonna leave you with this and ask you to spot the error there's an error in the C code trust me unfortunately we're running out of time so I will not give you no that was my mistake I guess no the error is something different yes I did not divide by size of actually GCC complains to you and says you're accessing out of bounds clan didn't whereas this the C++ code is much simpler to close there's a bunch of goodies that we're doing in C++ 14 and C++ 17 I don't have the time to explain them all the language is evolving rapidly where C is not so much it's all an ISO standard but interestingly the standard itself can be found on github you can compile it because it stacks they only accept all requests for editorial changes everything else needs to go through meaningless discussions which we're familiar with so unfortunately I ran out of time thank you so much for coming I'm available in the coffee area afterwards yes and UC++