Guest connection: login: Guest, password: anonymous

User Tools

Site Tools


Introduction aux concepts des langages de programmation


Les projets

La page des projets

Correctif pour la bibliothèque “screen”

Cours 12: C++ avancé


Mardi 3 décembre

  • Passage d'arguments en ligne de commande
  • Exceptions
  • Templates
  • Opérateurs: [], ()

Les programmes vus en cours: argc/argv, throw/catch, template<…>

Documentation C++: tutoriaux

Templates and multiple-file projects

From the point of view of the compiler, templates are not normal functions or classes. They are compiled on demand, meaning that the code of a template function is not compiled until an instantiation with specific template arguments is required. At that moment, when an instantiation is required, the compiler generates a function specifically for those arguments from the template.

When projects grow it is usual to split the code of a program in different source code files. In these cases, the interface and implementation are generally separated. Taking a library of functions as example, the interface generally consists of declarations of the prototypes of all the functions that can be called. These are generally declared in a “header file” with a .h extension, and the implementation (the definition of these functions) is in an independent file with c++ code.

Because templates are compiled when required, this forces a restriction for multi-file projects: the implementation (definition) of a template class or function must be in the same file as its declaration. That means that we cannot separate the interface in a separate header file, and that we must include both interface and implementation in any file that uses the templates.

Since no code is generated until a template is instantiated when required, compilers are prepared to allow the inclusion more than once of the same template file with both declarations and definitions in a project without generating linkage errors.

Cours 11: Allocation dynamique

vendredi 29 novembre

  • Mémoire physique et mémoire virtuelle
  • Pile et tas, stratégies de gestion du tas
  • New et delete
  • Classes dynamiques: constructeur, destructeur, copie, affectation
  • Applications aux tableaux dynamiques 1D et 2D

Les programmes vus en cours: gestion du tas, classe dynamique

Documentation C++
  • New: This header describes functions used to manage dynamic storage in C++.
  • Memory elements: This header defines general utilities to manage dynamic memory.
La minute culture: fuites mémoire

In computer science, a memory leak occurs when a computer program incorrectly manages memory allocations. In object-oriented programming, a memory leak may happen when an object is stored in memory but cannot be accessed by the running code. A memory leak has symptoms similar to a number of other problems (see below) and generally can only be diagnosed by a programmer with access to the program. Because they can exhaust available system memory as an application runs, memory leaks are often the cause of or a contributing factor to software aging. Memory leak, Wikipedia

Quelques outils
  • GDB et son interface graphique DDD. Beaucoup de tutoriels sont disponibles: voir par exemple celui de Daniel Hirschkoff, en charge du cours Programmation à l'ENS Lyon.
  • Valgrind, la Rolls des outils d'analyse. Malheureusement très dépendant de la version du système, n'existe souvent pas encore pour les versions les plus récentes.

Cours 10: Pointeurs et STL

Vendredi 22 novembre

  • Pointeurs
  • Arithmétique pointeur
  • Standard Template Library
  • Itérateurs
Documentation C++
La minute culture: TOP500

Twice a year, three Top500 lists come out to rank the world's supercomputers by either their overall performance, their ability to parse enormous data sets, or their minimal environmental impact. And last week the Top500, Graph500 and Green500 were released at the SC13 conference in Denver.

For more than 20 years, the Top500 list has used analysis of brute force computing power, the number of floating-point operations each machine could process per second, to determine the rankings for supercomputers. But parsing data and reducing environmental impact are two trends that have led to the Graph500 and Green500 lists.

The Green500 list provides a window into how difficult it is to build a supercomputer that can compete in terms of efficiency and low energy consumption. Only one supercomputer on this year's Green500, the Piz Dainte from the Swiss National Supercomputing Centre, is also ranked in the top 10 of the Top500.

Most Efficient Supercomputers Ranked On Green500 List, Lily Hay Newman, IEEE Spectrum Nov 2013

Cours 9: Héritage et virtualisation

Vendredi 15 novembre

  • Héritage et visibilité
  • Virtualisation
  • Compléments: éléments statiques, operator < <
Documentation C++
Bjarne Stroustrup

Le concepteur de C++ est aussi un grand communicant, ce qui a sans doute significativement contribué à la large adoption du langage. Son site personnel déborde d'informations. Vous y trouverez par exemple un grand nombre d'entretiens. Pour un exemple récent, voir Bjarne Stroustrup Discusses C++.

Il maintient une liste des principales questions qui ont été posées à propos de C++. Voir en particulier celles sur l'héritage.

  • Why are member functions not virtual by default?
  • Why don't we have virtual constructors?
  • What is a pure virtual function?
  • Why doesn't C++ have a final keyword?
  • Why doesn't C++ have a universal class Object?
  • Do we really need multiple inheritance?

Plus étonnant, il maintient aussi une liste des grandes applications développées en C++: Geant4, GCC, Google, Microsoft, etc.

Here is a list of systems, applications, and libraries that are completely or mostly written in C++. Naturally, this is not intended to be a complete list. In fact, I couldn't list a 1000th of all major C++ programs if I tried, and this list holds maybe 1000th of the ones I have heard of. It is a list of systems, applications, and libraries that a reader might have some familiarity with, that might give a novice an idea what is being done with C++, or that I simply thought “cool”. Bjarne Stroustrup, Applications

Cours 8: premiers pas en C++: classes et objects


Mardi 5 novembre

  • Hello world!
  • Classes: l'exemple des complexes
  • Références et passage de paramètres
  • Vecteurs
  • Éléments statiques
  • Le pointeur this

Le plus important: la documentation C++ en ligne

Les livres de la semaine
  • Votre nouveau livre de chevet: C++ for mathematicians, Ed Scheinerman and published by CRC Press. Le livre de référence du cours. Achat recommandé.
  • La Bible: The C++ programming language, Bjarne Stroustrup. Le livre où se trouvent les réponses à toutes les questions, même celles que vous n'auriez jamais pensé à poser!
  • Pour ceux qui connaissent un peu C++ et qui veulent approfondir les détails: Langage C++: les spécifications du standard ANSI/ISO expliquées, Jacquelin Charbonnel, Dunod. Le livre que j'utilise pour préparer mes cours C++ aux élèves d'informatique


The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity to work with was a language called Simula, which as the name implies is a language primarily designed for simulations. The Simula 67 language - which was the variant that Stroustrup worked with - is regarded as the first language to support the object-oriented programming paradigm. Stroustrup found that this paradigm was very useful for software development, however the Simula language was far too slow for practical use.

Shortly thereafter, he began work on “C with Classes”, which as the name implies was meant to be a superset of the C language. His goal was to add object-oriented programming into the C language, which was and still is a language well-respected for its portability without sacrificing speed or low-level functionality. His language included classes, basic inheritance, inlining, default function arguments, and strong type checking in addition to all the features of the C language.

[…] In mid-2011, the new C++ standard (dubbed C++11) was finished. The Boost library project made a considerable impact on the new standard, and some of the new modules were derived directly from the corresponding Boost libraries. Some of the new features included regular expression support (details on regular expressions may be found here), a comprehensive randomization library, a new C++ time library, atomics support, a standard threading library (which up until 2011 both C and C++ were lacking), a new for loop syntax providing functionality similar to foreach loops in certain other languages, the auto keyword, new container classes, better support for unions and array-initialization lists, and variadic templates.

Written by Albatross, History of C++

Cours 7: premiers pas en C

Vendredi 25 octobre

  • Hello world!
  • Types de base
  • Constructeurs de types: struct, union, enum
  • Expressions, affectations
  • Structures de contrôle
  • Fonctions, passage de paramètres
Les livres de la semaine
De la lecture pour cette semaine

Les discours de Turing Award de Thompson et Ritchie en 1983

  • Kenneth Lane Thompson: Reflections on Software Research, un article étonnamment d'actualité, même s'il a été écrit il y a plus de 30 ans.
  • Dennis MacAlistair Ritchie: Reflections on trustring trust. Probablement l'un des premiers articles sur la possibilité de fabrication de virus informatique. Lisez le début, mais essayez de trouver la solution tout seuls!


Cours 6: Ordre supérieur

Vendredi 18 octobre

  • Notion de continuation
  • Fonction usuelles
  • Continuations et exceptions
  • Continuations et itérateurs
Les livres de la semaine

Le livre d'Abelson et Sussman a eu un énorme impact sur l'enseignement de la programmation et la popularité de la programmation fonctionnelle en Scheme. Le livre est entièrement disponible en ligne, associé à un site Web qui rassemble une mine d'exercices et de projets passionnants. Voici un article qui explique l'importance de ce livre.

In 2011, to celebrate the 150th anniversary of MIT, the Boston Globe made a list of the most important innovations developed there. They asked me to explain the importance of SICP, and this is what I sent them:

SICP was revolutionary in many different ways. Most importantly, it dramatically raised the bar for the intellectual content of introductory computer science. Before SICP, the first CS course was almost always entirely filled with learning the details of some programming language. SICP is about standing back from the details to learn big-picture ways to think about the programming process. It focused attention on the central idea of abstraction – finding general patterns from specific problems and building software tools that embody each pattern. It made heavy use of the idea of functions as data, an idea that's hard to learn initially, but immensely powerful once learned. (This is the same idea, in a different form, that makes freshman calculus so notoriously hard even for students who've done well in earlier math classes.) It fit into the first CS course three different programming paradigms (functional, object oriented, and declarative), when most other courses didn't even really discuss even one paradigm.

[…] In my experience, relatively few students appreciate how much they're learning in my course while they're in it. But in surveys of all our CS students, it turns out to be among the most popular courses in retrospect, and I regularly get visits and emails from long-gone students to tell me about how they're using in their work ideas that they thought were impractical ivory-tower notions as students. The invention of the MapReduce software for data parallelism at Google, based on functional programming ideas, has helped eliminate that ivory-tower reputation.

Brian Harvey, University of California, Berkeley


Cours 5: Exceptions

Mardi 15 octobre

  • Notion d'exception
  • Exceptions Caml, harnais try/with
  • Exceptions et itération: break et continue
  • Exceptions et récursion


  • La recherche d'un élément dans un arbre
  • La vidéo de la semaine: The promise, the limits, and the beauty of software, Grady Booch, IBM Fellow. Transcription anglaise disponible. Grady Booch is an IBM Fellow and the author of numerous books on software design and architecture as well as volumes on UML (which he co-developed with Ivar Jacobsen and James Rumbaugh). In 2007, Grady stopped by Yahoo! to meet with Yahoo! software architects and, while here, he gave an open lecture for engineers. This is a version of a lecture originally given to the British Computer Society in honor of Alan Turing.
  • L'article de la semaine: What really happened on Mars? et la réponse de Glenn Reeves, JPL, responsable du logiciel de la mission spatiale Mars Pathfinder en 1997.

Real-World (Out of This World) Story: The Mars Pathfinder mission was widely proclaimed as “flawless” in the early days after its July 4th, 1997 landing on the Martian surface. Successes included its unconventional “landing” – bouncing onto the Martian surface surrounded by airbags, deploying the Sojourner rover, and gathering and transmitting voluminous data back to Earth, including the panoramic pictures that were such a hit on the Web. But a few days into the mission, not long after Pathfinder started gathering meteorological data, the spacecraft began experiencing system resets. The press reported these failures in terms such as “software glitches” and “the computer was trying to do too many things at once”. Read What really happened on Mars? Also, be sure to read this follow-up message from Glenn Reeves of JPL, who led the software team for the Mars Pathfinder spacecraft. Michael B. Jones, Microsoft

Cours 4: Références et applications

4 octobre 2013

  • Notion de référence, égalité, identité
  • Effets de bord
  • Champs modifiables
  • Listes modifiables
  • Arbres modifiables


Language designers are forever searching for the “proper language” for a domain, task, or class of programs, such that everything – such as correctness, optimisations, abstractions, high-level structures, solutions to a problem, etc. – becomes clearer when the language is used. The four Rs capture the key aspects of programming language’s affect on programs, in its ability to improve reading, writing, running, and reasoning.

These are four important areas that we need to consider when designing effective languages. The four Rs are not meant to argue whether a language is “good” or “bad”, or to unilaterally promote one over the other. Instead, the four Rs provide a framework for thinking critically about the effectiveness of languages and language features. Trade-offs between the four Rs have given a broad and beautiful spectrum of programming languages over the last 70 years. I await further languages with excitement and hope that with better languages everything might become clearer.

The four Rs of programming language design, Dominic Orchard

Cours 3: Théorie des catégories, somme et produit

24 septembre 2013

  • Théorie des catégories
  • Produit et somme catégoriques
  • Application aux listes
  • Applications aux arbres


Abstract nonsense, or general abstract nonsense, is a popular term used by mathematicians to describe certain kinds of arguments and concepts in category theory or applications. The term goes back a long way, and even predates the foundation of category theory as a subject itself. Referring to a joint paper with Samuel Eilenberg that introduced the notion of a “category” in 1942, Saunders Mac Lane wrote the subject was 'then called “general abstract nonsense”'.

The term is believed to have been coined by the mathematician Norman Steenrod, himself one of the developers of the categorical point of view. This term is used by practitioners as an indication of mathematical sophistication or coolness rather than as a derogatory designation.

“Logical abstract nonsense is a subfield of general abstract nonsense”, Language Log

Cours 2: Approche par types abstraits: les listes

20 septembre 2013

  • Listes Ocaml
  • Notion de type abstrait: constructeurs, accesseurs, observateurs, combinateurs, notion d'interface de programmation (API)
  • Fonctions classiques: approches concrète et abstraites
  • Itérateurs: map et reduce



Cours 1: Introduction à Caml

10 septembre 2013

  • Historique, grands noms
  • Présentation générale: interprète interactif, synthèse de type, évaluation
  • Types et opérateurs de base: int, float, char, string, bool, synthèse de type
  • Fonctions: définition explicite, lambda-expressions, curryfication, ordre supérieur



Langages de programmation

Measuring programming language popularity It is difficult to determine which programming languages are most widely used, and what usage means varies by context. One language may occupy the greater number of programmer hours, a different one have more lines of code, a third may utilize the most CPU time, and so on. Some languages are very popular for particular kinds of applications. For example, COBOL is still strong in the corporate data center, often on large mainframes; FORTRAN in engineering applications; C in embedded applications and operating systems; and other languages are regularly used to write many different kinds of applications.





Théorie des catégories



Outils, environnements de programmation, etc.


Documentation C++ de référence: The C++ Resources Network

Tout le cours est construit sur le compilateur GNU g++ version 4.8 et les outils GNU standard: make, gdb, etc. Nous utiliserons aussi des outils avancés comme valgrind. L'environnement recommandé est Linux Ubuntu, mais vous pouvez tout à fait travailler sur Windows ou Mac.

Attention cependant, les projets sont corrigés sous Linux Ubuntu. C'est votre responsabilité que de vérifier que tout marche bien dans cet environnement si vous développez autrement.

Un environnement de développement recommandé: Geany

Geany is known to run under Linux, FreeBSD, NetBSD, OpenBSD, MacOS X, AIX v5.3, Solaris Express and Windows. More generally, it should run on every platform, which is supported by the GTK libraries. Only the Windows port of Geany is missing some features.

Un site ressource sur les environnements de développement C++: la page Wikipedia sur les environnements de développement intégré (EDI)

dit/cours/prog1_2013-14.txt · Last modified: 2018/09/09 17:21 by luc.bouge