Modular C - Inria - Institut national de recherche en sciences et technologies du numérique Access content directly
Reports (Research Report) Year : 2015

Modular C

Abstract

We propose an extension to the C standard called Modular C. It consists in the addition of a handful of directives and a naming scheme transforming traditional translation units into modules. The change to the C language is minimal since we only add one feature, composed identifiers, to the core language. Our modules can import other modules as long as the import relation remains acyclic and a module can refer to its own identifiers and those of the imported modules through freely chosen abbreviations. Other than traditional C's #include, our import directive ensures complete encapsulation between modules. The abbreviation scheme allows to seamlessly replace an imported module by another one with equivalent interface. In addition to the export of symbols, we provide parameterized code injection through the import of ``snippets''. This implements a mechanism that allows for code reuse, similar to X macros or templates. Additional features of our proposal are a simple dynamic module initialization scheme, a structured approach to the C library and a migration path for existing software projects. The whole approach is validated by a formal description of a translation procedure from Modular C to common C and a proof of the correctness of that procedure. Thereby we are able to show that the class of stable programs can effectively be expressed in Modular C and that the gain of modularity is not thwarted by a loss of expressiveness. Here stable programs are those that do not use extensive C macro facilities that manipulate identifiers. Our approach is implemented and used successfully and efficiently in several projects. Interfaces can easily be provided both ways, to interface existing projects for Modular C or to interface Modular C libraries with other programming languages
Nous proposons une extension au langage de programmation C, nommé C modulaire. Elle consiste en ajoutant une poignée de directives et d’un schéma de nommage à transformer des unités de traduction traditionnelles en module. La modification au language-même est minimale, car nous y ajoutons une seul nouvelle caractéristique, les identifiants composés. Nos modules peuvent importer autre modules tant que la relation d’import reste acyclique et un module peut référer à ses propres identifiants et ceux des modules importés à l’aide d’abréviations librement choisis. Autre que l’include traditionnel, notre directive d’import assure l’encapsulation complète entre modules. Le schéma d’abréviation permet de facilement remplacer un module importé par un autre qui réalise le même interface. En plus à l’export de symboles nous fournissons l’injection de code paramétré par l’importation de snippets. Ceci implante un mécanisme de réutilisation de code, similaire au X-macro ou template. Des outils supplémentaires que propose notre approche sont un schéma d’initialisation, un approche structuré à la bibliothèque standard de C et un chemin de migration pour des projets de logiciel existants.
Fichier principal
Vignette du fichier
RR-8751.pdf (1.07 Mo) Télécharger le fichier
Origin : Files produced by the author(s)
Loading...

Dates and versions

hal-01169491 , version 1 (29-06-2015)
hal-01169491 , version 2 (12-07-2015)
hal-01169491 , version 3 (24-01-2018)
hal-01169491 , version 4 (12-06-2018)

Identifiers

  • HAL Id : hal-01169491 , version 4

Cite

Jens Gustedt. Modular C. [Research Report] RR-8751, INRIA. 2015. ⟨hal-01169491v4⟩
553 View
1973 Download

Share

Gmail Facebook X LinkedIn More