# Implementing a declarative mini-language in the C preprocessor

DevFeed: [Implementing a declarative mini-language in the C preprocessor](<https://devfeed.tech/articles/implementing-a-declarative-mini-language-in-the-c-preprocessor-21912.md>)

Original publisher: [Read original article](<https://blog.nelhage.com/2010/07/implementing-an-edsl-in-cpp/>)

Author: Nelson Elhage

Published: 2010-07-04T15:54:55Z

Content type: tutorial

Language: en

Sources: [Nelson Elhage](<https://devfeed.tech/sources/nelson-elhage.md>)

Topics: [Code](<https://devfeed.tech/topics/code.md>), [C](<https://devfeed.tech/topics/c.md>), [gcc](<https://devfeed.tech/topics/gcc.md>), [test](<https://devfeed.tech/topics/test.md>)

Tags: [arrays](<https://devfeed.tech/tags/arrays.md>), [c](<https://devfeed.tech/tags/c.md>), [code](<https://devfeed.tech/tags/code.md>), [declarative](<https://devfeed.tech/tags/declarative.md>), [function](<https://devfeed.tech/tags/function.md>), [gcc](<https://devfeed.tech/tags/gcc.md>), [language](<https://devfeed.tech/tags/language.md>), [pointers](<https://devfeed.tech/tags/pointers.md>), [test](<https://devfeed.tech/tags/test.md>)

## AI overview

This tutorial explains how to implement a declarative mini-language in the C preprocessor using global data structures, function pointers, ELF sections, and GCC extensions. The example supports defining Check test suites and test cases.

## Source excerpt

Last time, I announced Check Plus, a declarative language for defining Check tests in C. This time, I want to talk about the tricks I used to implement a declarative minilanguage using the C preprocessor (and some GCC extensions). The Problem We want to write some toplevel declarations that look like: #define SUITE_NAME example BEGIN_SUITE("Example test suite"); #define TEST_CASE core BEGIN_TEST_CASE("Core tests"); ... and so on, and somehow translate them into code that does the equivalent of: