Posts

C++: Undefined behaviour from realloc and the Clang Optimizer

Image
I was wondering around in some system code and found a strange behaviour between two modes in a piece of code, where the code switches from double to triple buffer mode there's a problem, we've already got two buffers of everything we just want to allocate another but the underlying structure for sets of buffers wants to own them all... So the code went from: SetOfBuffers { Buffer* one; Buffer* two; } To: SetOfBuffers { Buffer* one; Buffer* two; Buffer* three; } Creating the third buffer is fine: SetOfBuffers::three = malloc(X); But, the first two is a re-alloc, to reuse the existing buffer: SetOfBuffers::One = realloc(OldSet::one, X); SetOfBuffers::Two = realloc(OldSet::two, X); The problem?  I'd start to modify the values in the new set of buffers, the third buffer being used and present.  Then the first buffer would be changed present... The second buffer changed present and the information is wrong (I over simplify massively here). Anyway, I was remotely SSH'd ...

C++: The Dilemma of using Exceptions

Image
As a C++ developer I've recently been in the midst of the Exceptions debate.  Exceptions as a feature of the C++ language have long divided the community, naively I've often put this down to their coming to the language from elsewhere (C perhaps) where exceptions were not the norm. This was a mistake, for in the projects I've previously worked upon the overhead of an exception compared to the ramifications of the error resulting in a crash have often totally outweighed the overhead, making deciding to employ an exception exceptionally easy (*bum bum*).  Exceptions were the norm, still are and should be to you too (according to the C++ Core Guidelines https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Ri-except ). The difficulty, the dilemma if you will, comes not from the feature, but the cost.  If you application domain demands high performance you can not risk using exceptions, the argument carries on therefore whether in not using them to avoi...

Cross Compiling Clarity

I have an important distinction to make clear... Cross Compiling is using a machine with a different processor type than the target machine for your program. So, you have a PC with an Intel Core 2 Duo in it, and you use a compiler to output an ARM executable, that is cross compiling. If you're on an Intel Core Duo toting 15" MacBook pro (from 2006 ) and you use that to produce the same ARM executable, that's still cross-compiling.  BUT if you use that MacBook to generate a windows executable it's not cross compiling, as the processor is the same in both targets, you're not crossing over... Some folks argue this differently, because you're crossing between the Windows and Apple OS's you're cross-compiling.  In my book, and by the definition given elsewhere, you're not, in this case you are cross-platform (the platform being the OS) but you're not cross compiling because the processors are the same family. That's all, I just wanted this out t...

Programmer Between Jobs...

Image
Announcement time, I'm unemployed... Yes, as of the 28th December 2018 I have not been gainfully employed.  But fear not, I am starting my new job on Wednesday 2nd January. I've covered this in a nattering brief on my YouTube, which I now link, but stick with this post for more information. I've never really spoken directly about the job I've had and how its evolved over the years I've been with it, so I was at that role for 14 years.  That's a very long time, especially in today's markets, but as you all know I keep myself busy and informed on these very pages. I did work in what's euphemistically called "the pay to play industry", this is the gambling industry to the rest of the world, but saying that I didn't write the actual games.  I was a systems engineer, so I wrote software which drove the money accepting and paying hardware, and especially software which worked to store the current state of a machine, avoid frauds, count, collate a...

C++ High Performance - Mistaken Statements

Image
I am a huge fan of using the language to communicate my intent, especially when it comes to function parameters, I've talked about this before in terms of simple typing (by utilising "using" statements - to give meaning to simple/trivial types) and const correctness. But being Christmas, I've had a C++ gift or two, and one of them is C++ High Performance by Victor Sehr and Bjorn Andrist , I've only spent a few minutes looking through this book, but one comment did jump out at me as odd... Not overtly wrong, just odd to me, maybe a different way to look at things... No, I'm not talking about their constant calling back to compare with Java (rolls eyes) I'm talking about the two stanza's at the bottom: "C++ Arguments passed as references indicates that null values are not allowed" No, no that's not the point of references, the point is that you do not allocate memory for and copy the values from the passed resource into a local value for us...

Deep Thought about a new Laptop

Image
Its the day after THE day we wait for all year, yes today is Boxing Day and so yesterday was Christmas Day and I've had a fab day, thank you for asking!  Lots of food, a little drink, a fair amount of chocolate, a home made cheese cake to die for and about an hour in the freezing air enjoying the hot tub with all the bubbles on... Hands down has to rate as one of the Best Christmas Days for me ever... and I hope yours were all as good. Now, I know you're all asking, why have I been so quite on the old blog and YouTube Channel?  Well, you know moving house completely threw things off, but also, in case you missed this news, I'm changing jobs. Yes, after 14 years I'm leaving where I've been and I'm going to be doing something else.  Quite what I can't tell you very much about, probably for a fair while.  But what I can tell you is, I start the new role on the 2nd January, the team I have been assigned to is brand new and we travel to the US in mid-January to c...

Xelous Clothing Range

I was just wondering, whether these folks have realised that this overweight English and decidedly unstylish fellow typing this missive has been "xelous" since 1996... http://xelous.com Not the best search results for them from my point of view. P.S. I am also NOT the Orc Warlock... Alliance represent!

Plastering Machine Required

So, the move is over... So many little jobs have been completed, from wiring, changing switches and today plastering a wall from which the pink finish had crumbled (no idea why the prior owner left it to get in such a state, it only took an hour to strip, brush, seal with PVA and replaster... Which brings me onto the topic of today's post... An invention... Which mixes plaster... Yes, this would be a huge money maker, but there must be a reason it doesn't exist on the domestic market.... Now I'm pretty sure there will be a huge hundred grands worth of professional mixing machine somewhere, but I'm talking about the small job, a single wall or room in a home. What might this need?... Well, it needs some sensors for the mix, thickness/turbidity, water, weight, temperature even?  You pour the dry powder in some hopper, it's tested, you set the mix type (finishing or main coat etc) the water is maybe filled straight from a tap to the machine... and the computer does the...

Sana-fracin-down-dirty GGRRRRRR

Smashed my phone whilst lifting the old dishwasher out... This house move just got a whole lot more expensive.

Budding Programmers.... Subscription to Learn

Harping back to my prior post about learning to program, when I spoke at my old Uni, I spoke to a lovely trio of ladies, whom wanted to be programmer/computer folks... And one thing struck me, was how narrow their knowledge was. When they asked me how I got into programming and I explained that when I learned to program in the 1990's there was no github, indeed there was no internet, you could not just go and download a program or join an open source project.  If you wanted tool, and had no BBS dial up to find someone with something like it, you wrote your own. I wrote code to record kills in games on the Atari ST, I wrote text editors for the ST and DOS (EGA graphics FTW), I write 2D painting programs for DOS.... I distinctly remember my college tutor seeing my using DOS interrupt 11 to control the mouse and his saying "you're the first person I've seen work that out"... I didn't work it out by trial and error though, I worked it out by reading, about the DOS...