Defining C Preprocessor Macro Libraries with Functional Programs

Authors

  • Boldizsár Németh Eötvös Loránd University, Budapest
  • Máté Karácsony Eötvös Loránd University, Budapest
  • Zoltán Kelemen Eötvös Loránd University, Budapest
  • Máté Tejfel Eötvös Loránd University, Budapest

Keywords:

C preprocessor, functional programming, Haskell, program transformation, transcompiler

Abstract

The preprocessor of the C language provides a standard way to generate code at compile time. However, writing and understanding these macros is difficult. Lack of typing, statelessness and uncommon syntax are the main reasons of this difficulty. Haskell is a high-level purely functional language with expressive type system, algebraic data types and many useful language extensions. These suggest that Haskell code can be written and maintained easier than preprocessor macros. Functional languages have certain similarities to macro languages. By using these similarities this paper describes a transformation that translates lambda expressions into preprocessor macros. Existing compilers for functional languages generate lambda expressions from the source code as an intermediate representation. As a result it is possible to write Haskell code that will be translated into preprocessor macros that manipulate source code. This may result in faster development and maintenance of complex macro metaprograms.

Downloads

Download data is not yet available.

Downloads

Published

2017-02-07

How to Cite

Németh, B., Karácsony, M., Kelemen, Z., & Tejfel, M. (2017). Defining C Preprocessor Macro Libraries with Functional Programs. Computing and Informatics, 35(4), 819–851. Retrieved from http://147.213.75.17/ojs/index.php/cai/article/view/3380

Issue

Section

Special Section Articles