background preloader

C++ FAQ

C++ FAQ

cpp:meta_prog [Jean-Paul Rigault] Nouveautés Présentation Ce cours donne quelques compléments sur une utilisation avancée de C++, utilisant en particulier la bibliothèque Boost et le techniques de méta-programmation par “templates”. Pour une motivation et une introduction rapide à ces techniques, voir l'annonce du cours. Ce cours est aussi une introduction à quelques unes des extensions les plus importantes de la norme C++ 2011. Organisation du cours Le cours a lieu en général le mardi après-midi, à raison de 4 heures par semaine : 6 séances (plus une) au total. Ce module est constitué d'une alternance de cours et de travaux pratiques. Environnement de développement Le cours a lieu sous Linux exclusivement. Vous êtes libre de choisir votre environnement de développement favori (Emacs, Eclipse, KDevelop, Code::Blocks, etc.) du moment que vous avez appris à l'utiliser. Installation de gcc-4.8.1 sous Ubuntu 12.04 Suivez les instructions de cette page Web qui sont très simples et très claires. Documents et ressources diverses

Debugging Memory Leaks, Part 2: CRT support « Ofek's Visual C++ stuff - Iceweasel Problem and Immediate Solution If you’re developing MFC apps, the way you’ll usually notice any leaks is by terminating your app and seeing the following in the output window: Detected memory leaks! Dumping objects -> C:\myfile.cpp(20): {130} normal block at 0x00780E80, 64 bytes long. Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD Object dump complete. the {130} is emphasized on purpose – it is the serial number of the leaking allocation. Well, it might not be that easy. Now if the serial number is consistent, what allocations exactly does it count? Happily, there is an easy solution to the second set of worries. _CrtSetBreakAlloc(130) Mid-depth Dive The allocation counter resides in the undocumented _heap_alloc_dbg, which channels calls from all C allocators – namely new, malloc, and their brethren (_malloc_dbg, aligned /offset flavours, etc.). When you do set an allocation breakpoint, you’d (naturally) break in the counting function itself, _heap_alloc_dbg. Bonus Like this:

CodeGuru: STL.NET: Combining Generics and Templates It has been jokingly suggested that when a C++ programmer is asked how to accomplish a given task, he or she will provide a list of a dozen or more potential solutions, and then proceed to outline the problem with each in excruciating detail. Visual C++ 2005, through the C++/CLI language bindings, introduces the concept of generics, allowing C++ programmers to further enhance their reputation as the programmers with the largest arsenal of language constructs. Brent Rector covered the differences between .NET generics and C++ templates in an excellent article in June 2004. The difference between templates and generics leads to the question that every C++ programmer who wants to target .NET will end up asking: Which technology should I pick? Leverage C++ Skills for .NET Development In the past, Visual C++ has offered some technologies that have enabled STL collections to work with other technologies. Bridging Templates and Generics Using STL.NET C++ Programmers' Ticket to the .NET Realm

Reference This website uses cookies. By continuing, you give permission to deploy cookies, as detailed in our privacy policy. ok Search: Reference Not logged in Reference Standard C++ Library reference C Library The elements of the C language library are also included as a subset of the C++ Standard library. <cassert> (assert.h) C Diagnostics Library (header) <cctype> (ctype.h) Character handling functions (header) <cerrno> (errno.h) C Errors (header) <cfenv> (fenv.h) Floating-point environment (header) <cfloat> (float.h) Characteristics of floating-point types (header) <cinttypes> (inttypes.h) C integer types (header) <ciso646> (iso646.h) ISO 646 Alternative operator spellings (header) <climits> (limits.h) Sizes of integral types (header) <clocale> (locale.h) C localization library (header) <cmath> (math.h) C numerics library (header) <csetjmp> (setjmp.h) Non local jumps (header) <csignal> (signal.h) C library to handle signals (header) <cstdarg> (stdarg.h) Variable arguments handling (header) <cstdbool> (stdbool.h) Containers

Pointeurs intelligents Avant de voir les différents types de pointeurs intelligents, il est utile de revenir sur les pointeurs classiques du C++, que je nommerai pointeurs nus par opposition aux pointeurs intelligents. Ces pointeurs présentent un certain nombre de problèmes qui en rendent l'usage difficile et risqué, les différents pointeurs intelligents ayant pour objectif de corriger ces problèmes. Il y a globalement trois risques d'erreur, et un problème de clarté, avec les pointeurs nus. II-A-1. A partir du moment où on alloue dynamiquement de la mémoire, il faut la désallouer quand on a fini de s'en servir. Cette contrainte pose deux problèmes : Elle oblige déjà à une grande discipline de codage, afin de ne pas oublier un delete quelque part, et en plus, elle est très difficile à mettre en œuvre correctement. Dans ces deux cas, on peut penser avoir correctement fait le travail de désallocation. Dans le second cas, même problème, si le new int(42) échoue, par manque de mémoire, une exception est lancée.

Debugging Native Memory Leaks, Part 1: LeakDiag « Ofek's Visual C++ stuff - Iceweasel Leaking memory is probably the single most painful aspect of native code – its the reason managed was ever born. Sadly, this is useful only in the handful of cases where the code allocates directly. What if the offending allocation is performed via some common container routine? Even worse – what if the leak is properly de-allocated in destructors at shutdown time? The CRT support would be of no use. There are two powerful, free, and vastly different tools from Microsoft, that achieve just that. Enter LeakDiag! I’m actually not sure how public this tool is. LeakDiag does its magic by using Detours technology (fascinating read!) To demonstrate, consider the leaking code here (adapted from a UMDH demo) : Start LeakDiag and run your program. This activates the API interception in your selected process (LeakyApp.exe), for your selected API (CRT allocator). Focus back to LeakyApp.exe and press any key. Click anything again to end the program. Start LDGrapher. Like this: Like Loading...

Compilers and Compiler Generators Special Symbols | Contents | Diagrams | Symbol Font Edition | GIF Font edition | Downloadable files | Source Code | Courseware | Change List an introduction with C++ © P.D. Terry, Rhodes University, 1996 NEW (1 February 2005) The complete text of the book has been distilled into one PDF file (1MB) pdfvers.pdf, courtesy of Irwin Oppenheim of the Netherlands. NEW (23 November 2004) A complete revision of this book, using C# and Java and the versions of Coco/R for those languages, was published by Pearson Education (Addison Wesley) on 5th November 2004 under the title "Compiling with C# and Java" (ISBN 032126360X). A feature of this book is that it demonstrates the use of Coco/R to implement compilers for the JVM and CLR platforms. You can view the contents of the freely available "Resource Kit". You might also like to view the Pearson Education catalogue entry for this book. Order it from www.amazon.co.uk (February 2003) Local site reorganization: A previous ftp server has been decommissioned.

Essential Math for Games Programmers As the quality of games has improved, more attention has been given to all aspects of a game to increase the feeling of reality during gameplay and distinguish it from its competitors. Mathematics provides much of the groundwork for this improvement in realism. And a large part of this improvement is due to the addition of physical simulation. This tutorial deepens the approach of the previous years' Essential Math for Games Programmers, by spending one day on general math topics, and one day focusing in on the topic of physical simulation. Topics for the various incarnations of this tutorial can be found below. Current Materials Slides The latest available versions of the slides for the math tutorials at GDC 2015 are as follows: See below for further materials from past years that may be useful. Past Materials Presentations for the math tutorials at GDC 2014 are as follows: Presentations for the math tutorials (the physics presentations are available here) at GDC 2013 are as follows:

La Programmation en C++ - Un tout premier programme : l'incontournable "Hello World!" Un tout premier programme : l'incontournable "Hello World!" Le "Hello, World!" semble être une véritable tradition dans le monde de la programmation. Je crois que je n'ai pas trouvé un seul livre sur leC/C++ qui ne commence par cet exemple, donc je vais faire de même. Dans ce cours, nous allons commencer par écrire le programme, puis nous le commenterons ligne par ligne. Je n'aime pas trop cette approche, mais ce premier petit programme nous permet de mettre au point quelques connaissances de base très importantes qu'il faudra retenir. Les chiffres sur la gauche sont juste là pour indiquer le numéro de chaque ligne, ils ne font pas partie du programme. Vous voyez, c'est... pas si simple que ça. L'instruction principale, c'est clairement le cout << "Hello, World! On voit ensuite que cette instruction principale est enfermée dans un bloc {} (lignes 3 et 5). Notez bien que main() s'écrit avec des minuscules. Voici les points essentiels à retenir: Voir aussi: chaîne de caractères - déclaration

Error and Exception Handling - Iceweasel References The following paper is a good introduction to some of the issues of writing robust generic components: D. Abrahams: ``Exception Safety in Generic Components'', originally published in M. Jazayeri, R. Loos, D. Guidelines When should I use exceptions? The simple answer is: ``whenever the semantic and performance characteristics of exceptions are appropriate.'' An oft-cited guideline is to ask yourself the question ``is this an exceptional (or unexpected) situation?'' A more appropriate question to ask is: ``do we want stack unwinding here?'' How should I design my exception classes? What About Programmer Errors? As a developer, if I have violated a precondition of a library I'm using, I don't want stack unwinding. Sometimes it is necessary to have resilient APIs which can stand up to nearly any kind of client abuse, but there is usually a significant cost to this approach. How should I handle exceptions? Often the best way to deal with exceptions is to not handle them at all.

Boost C++ Libraries Style d'indentation L'indentation se définit par la manière d'arranger les blocs de code, mais surtout par le nombre d'espaces utilisés à chaque niveau. Styles d'indentation en C[modifier | modifier le code] Style K&R[modifier | modifier le code] void a_function(void){ if (x == y) { something1(); something2(); } else { somethingelse1(); somethingelse2(); } finalthing();} Il existe de nombreuses variantes de ce style. Une autre nuance couramment rencontrée peut venir du placement du mot-clé else. Style Allman[modifier | modifier le code] Nommé d'après Eric Allman, ce style respecte un alignement strict des accolades ouvrantes et fermantes, comme dans l'exemple ci-dessous : L'avantage principal de ce style est qu'on peut visuellement repérer très facilement tout oubli d'accolade. Style Whitesmiths[modifier | modifier le code] if (x == y) { something1(); something2(); }else { somethingelse1(); somethingelse2(); }finalthing(); Style GNU[modifier | modifier le code] Style Pico[modifier | modifier le code]

An introduction to C++ Traits - Iceweasel It is not uncommon to see different pieces of code that have basically the same structure, but contain variation in the details. Ideally we would be able to reuse the structure, and factor out the variations. In 'C' this might be done by using function pointers, as in the C Standard Library qsort function or in C++ by using virtual functions. Unfortunately this differed to runtime what is known at compile time, and became with a runtime overhead. C++ introduces generic programming, with templates, eliminating the need for runtime binding, but at first glance this still looks like a compromise, after all, the same algorithm will not work optimally with every data structure. The C++ traits technique provides an answer. Think of a trait as a small object whose main purpose is to carry information used by another object or algorithm to determine "policy" or "implementation details". - Bjarne Stroustrup Note the use of numeric_limits. Add to that a specialisation for void: And that's it.

GCC Home Page

Related: