background preloader

C++

Facebook Twitter

C++ Soup! Make Tutorial: How-To Write A Makefile - Michael Safyan. At some point in your computer programming career, you are likely to come across an abomination like the following: main.o : main.c gcc -c main.c -o main.o Not only is the above rule redundant (Make can figure out that "main.o" depends on "main.c" automatically, and can figure out how to build "main.o" from "main.c" without being told how to do so explicitly), but the above is also incredibly detrimental to your build.

Make Tutorial: How-To Write A Makefile - Michael Safyan

By ignoring $(CFLAGS) and $(CPPFLAGS), for example (which would not be ignored by the builtin rule for generating "main.o" from "main.c"), every such rule would have to be updated in order to support extra warnings or to add an additional header file search path (whereas, relying on the builtin rules, all object files would be built properly only be changing the CFLAGS and CPPFLAGS variables).

In addition, by hard-coding gcc, it is no longer possible to use a different compiler. Conventional Targets Explaining the 1 Minute Makefile # This is a place holder. A list of open source C++ libraries. The objective of this page is to build a comprehensive list of open source C++ libraries, so that when one needs an implementation of particular functionality, one needn't to waste time searching on web (DuckDuckGo, Google, Bing e.t.c).

A list of open source C++ libraries

If you know a library that might be useful to others, please add a link to it here. There are no restrictions on what can be included except that the source of the library must be readily available to download. The page is provided 'as is' - with the hope of being useful, but without any warranties. Outdated, misleading or wrong links might appear here. If you've noticed one of these, it would be great if you fixed the error.

[edit] Generic. MPprogramming.com. Castor : Logic paradigm for C++ Traditional approach to problem solving with computers is all about instructing the computer exactly how to solve the problem.

MPprogramming.com

This is called the Imperative paradigm and is based on the Turing machine. Languages such as C, C++, Java, Fortran etc. are all rooted in this paradigm. The Logic paradigm (LP) is a declarative programming model. Instead of instructing the computer how to solve a particular problem, we describe the problem domain as facts and rules. Logic programming is one approach in computer science towards what is sometimes referred to as the Holy Grail of programming: "The user states the problem, the computer solves it". Prolog is the best known programming language that supports logic programming. Tutorial · kripken/emscripten Wiki. Emscripten Tutorial Emscripten is an open source LLVM to JavaScript compiler.

Tutorial · kripken/emscripten Wiki

With it, you can compile C and C++ code into JavaScript and run it on the web. And it's easy! Портируем C/C++ библиотеку на JavaScript (xml.js) The LLVM Compiler Infrastructure Project. Projects built with LLVM This page is an incomplete list of the projects built with LLVM, sorted in reverse chronological order.

The LLVM Compiler Infrastructure Project

The idea of this list is to show some of the things that have been done with LLVM for various course projects or for other purposes, which can be used as a source of ideas for future projects. Smart Pointer Programming Techniques - 1.53. Using incomplete classes for implementation hiding A proven technique (that works in C, too) for separating interface from implementation is to use a pointer to an incomplete class as an opaque handle: class FILE; FILE * fopen(char const * name, char const * mode); void fread(FILE * f, void * data, size_t size); void fclose(FILE * f);

Smart Pointer Programming Techniques - 1.53

C++ - What is The Rule of Three. C++ - What is the copy-and-swap idiom. Libb64: Base64 Encoding/Decoding Routines. 1024cores. An Idiot's Guide to C++ Templates - Part 1. Prolusion Most C++ programmers stay away from C++ templates due to their perplexed nature.

An Idiot's Guide to C++ Templates - Part 1

The excuses against templates: Hard to learn and adapt. Compiler errors are vague, and very long. Not worth the effort. Admitted that templates are slightly hard to learn, understand, and adapt. While C++ templates and STL (Standard Template Library) are siblings, technically. Table of Contents The Syntax Drama As you probably know, template largely uses the angle brackets: The less than ( < ) and the greater than ( > ) operators. Where Content can be: class T / typename T A data type, which maps to T An integral specification An integral constant/pointer/reference which maps to specification mentioned above. Producer-Consumer Queues - 1024cores. Producer-consumer queues are one of the most fundamental components in concurrent systems, they represent means to transfer data/messages/tasks/transactions between threads/stages/agents.

Producer-Consumer Queues - 1024cores

If you hope that there is a single magical "one-size-fits-all" concurrent queue (MS PPL and Intel TTB fallacy), sorry, there is no. So what flavours of queues are there? I hope this aspect is clear - for example, if you have only 1 producer and 1 consumer thread, you can use SPSC queue instead of more general MPMC queue, and as you may guess it will be significantly faster. A gentle introduction to Template Metaprogramming with C++ Download demo project - 65 Kb Background A while ago I was working on a program that used a large lookup table to do some computations.

A gentle introduction to Template Metaprogramming with C++

The contents of the table depended on a large number of parameters that I had to tweak to get optimal performance from my code. C++ Annotations Version 9.6.0. Don't hesitate to send in feedback: send an e-mail if you like the C++ Annotations; if you think that important material was omitted; if you find errors or typos in the text or the code examples; or if you just feel like e-mailing.

C++ Annotations Version 9.6.0

Send your e-mail to Frank B. Brokken. Please state the document version you're referring to, as found in the title (in this document: 9.8.2) and please state chapter and paragraph name or number you're referring to. All received mail is processed conscientiously, and received suggestions for improvements are usually processed by the time a new version of the Annotations is released. Except for the incidental case I will normally not acknowledge the receipt of suggestions for improvements. Bind.hpp documentation - 1.53. Contents Purpose Using bind with functions and function pointers Using bind with function objects Using bind with pointers to members Using nested binds for function composition Overloaded operators Examples.

Other considerations and tips - 1.41. Native typeof support and emulation Many compilers support typeof already, most noticeable GCC and Metrowerks. Igor Chesnokov discovered a method that allows to implement typeof on the VC series of compilers. It uses a bug in the Microsoft compiler that allows a nested class of base to be defined in a class derived from base:

Tutorial - 1.53. Boost.Function has two syntactical forms: the preferred form and the portable form. The preferred form fits more closely with the C++ language and reduces the number of separate template parameters that need to be considered, often improving readability; however, the preferred form is not supported on all platforms due to compiler bugs. The compatible form will work on all compilers supported by Boost.Function. Preprocessor. Kahan summation algorithm. In numerical analysis, the Kahan summation algorithm (also known as compensated summation [1]) significantly reduces the numerical error in the total obtained by adding a sequence of finite precision floating point numbers, compared to the obvious approach. This is done by keeping a separate running compensation (a variable to accumulate small errors). In particular, simply summing n numbers in sequence has a worst-case error that grows proportional to n, and a root mean square error that grows as The algorithm is attributed to William Kahan.[3] Similar, earlier techniques are, for example, Bresenham's line algorithm, keeping track of the accumulated error in integer operations (although first documented around the same time[4]) and the Delta-sigma modulation[5] (integrating, not just summing the error).

The algorithm[edit] In pseudocode, the algorithm is: Worked example[edit] This example will be given in decimal. More C++ Idioms/Expression-template. Intent[edit] To create a domain-specific embedded language (DSEL) in C++To support lazy evaluation of C++ expressions (e.g., mathematical expressions), which can be executed much later in the program from the point of their definition.To pass an expression -- not the result of the expression -- as a parameter to a function. Also Known As[edit] Motivation[edit] Domain-specific languages (DSLs) is a way of developing programs where the problem to be solved is expressed using notation that is much closer to the domain of the problem rather than the usual notation (loops, conditionals, etc.) provided by procedural languages. C++ Expression Templates. The C++ Template Argument Deduction.