background preloader

C/C++

Facebook Twitter

Development blog: Sensible Error Handling: Part 1. To err is human.

development blog: Sensible Error Handling: Part 1

But it is also quite computery. Unfortunately, error handling tends to bring out the worst in APIs. Revenge of the Nerds. May 2002 In the software business there is an ongoing struggle between the pointy-headed academics, and another equally formidable force, the pointy-haired bosses.

Revenge of the Nerds

Everyone knows who the pointy-haired boss is, right? I think most people in the technology world not only recognize this cartoon character, but know the actual person in their company that he is modelled upon. The pointy-haired boss miraculously combines two qualities that are common by themselves, but rarely seen together: (a) he knows nothing whatsoever about technology, and (b) he has very strong opinions about it. Suppose, for example, you need to write a piece of software. Why does he think this? Well, this doesn't sound that unreasonable. But all languages are not equivalent, and I think I can prove this to you without even getting into the differences between them. Presumably, if you create a new language, it's because you think it's better in some way than what people already had.

So, who's right? Herb Sutter: (Not Your Father’s) C++ Life of an instruction in LLVM. LLVM is a complex piece of software.

Life of an instruction in LLVM

There are several paths one may take on the quest of understanding how it works, none of which is simple. I recently had to dig in some areas of LLVM I was not previously familiar with, and this article is one of the outcomes of this quest. What I aim to do here is follow the various incarnations an "instruction" takes when it goes through LLVM’s multiple compilation stages, starting from a syntactic construct in the source language and until being encoded as binary machine code in an output object file. This article in itself will not teach one how LLVM works.

It assumes some existing familiarity with LLVM’s design and code base, and leaves a lot of "obvious" details out. Input code I want to start this exploration process at the beginning – C source. Int foo(int aa, int bb, int cc) { int sum = aa + bb; return sum / cc; } The focus of this article is going to be on the division operation. Clang Here is the LLVM IR created for the function : Polymorphism in C. Introduction Polymorphism is by far the most important and widely used concept in object oriented programming.

Polymorphism in C

Some of the widely used technologies and libraries like COM, MFC etc. have polymorphism as their foundation. If you look at all the original design patterns, almost every pattern uses polymorphism in its structure. Incompatibilities Between ISO C and ISO C++ The C programming language began to be standardized some time around 1985 by the ANSI X3J9 committee.

Incompatibilities Between ISO C and ISO C++

Several years of effort went by, and in 1989 ANSI approved the new standard. An ISO committee ratified it a year later in 1990 after adding an amendment dealing with internationalization issues. C as an intermediate language. Here's a Forth program debugged in KDevelop - a graphical debugger without Forth support: Cool stuff, not?

C as an intermediate language

The syntax highlighting for Forth files - that's someone else's work that comes with the standard KDevelop installation. But the rest - being able to run Forth under KDevelop, place breakpoints, and look at program state - all that stuff is something we'll develop below. I'll show all the required code; we don't have to do very much, because we get a lot for free by using C as an intermediate language. A high-level intermediate language is not unusual. PortabilityOptimizationSome degree of library interoperabilitySome degree of tools interoperability (IDEs, debuggers, etc.) A few languages targeting high-level platforms are rather well-known: Scala and Clojure with compilers targeting the JVM, CoffeeScript and Dart which are compiled to JavaScript.

60+ Free programming books for C, C++, C# Understanding C by learning assembly. Last time, Alan showed how to use GDB as a tool to learn C.

Understanding C by learning assembly

Today I want to go one step further and use GDB to help us understand assembly as well. Abstraction layers are great tools for building things, but they can sometimes get in the way of learning. My goal in this post is to convince you that in order to rigorously understand C, we must also understand the assembly that our C compiler generates.

I'll do this by showing you how to disassemble and read a simple program with GDB, and then we'll use GDB and our knowledge of assembly to understand how static local variables work in C. Note: All the code in this post was compiled on an x86_64 CPU running Mac OS X 10.8.1 using Clang 4.0 with optimizations disabled (-O0*) Learning assembly with GDB Let's start by disassembling a program with GDB and learning how to read the output. Int main() { int a = 5; int b = a + 6; return 0; } Now compile it with debugging symbols and no optimizations and then run GDB: Registers Back to the code. Jason Mooberry » Blog Archive » What I learned from my first c coding challenge.