1 Getting Started
2 Libraries Provided by this Package
3 Known Limitations
4 Feedback and Bug Reports
5 History

C Metaprogramming Utilities

This package provides utilities for manipulating C programs.

1 Getting Started

The easiest way to get started using the C metaprogramming utilities is with the main module:

 (require (planet dherman/c:3:2))

This module provides everything in the entire package. Subsequent sections of this manual describe the functionality of the individual libraries included, which can also be required individually.

Examples:

> (define time.h
    (header
     (struct tm ([int tm_sec]
                 [int tm_min]
                 [int tm_hour]
                 [int tm_mday]
                 [int tm_mon]
                 [int tm_year]
                 [int tm_wday]
                 [int tm_yday]
                 [int tm_isdst]))))
> (define time
    (compile-header time.h
                    (system-compiler #:include<> '("time.h") gcc)))
> (layout-offset (time 'tm) 'tm_year)

20

Binary layout information is especially useful for interacting with the foreign library—see FFI: Racket Foreign Interface. For example, the procedures ptr-ref and ptr-set! can be used to read and write from arbitrary addresses, which can be computed using layout information.

2 Libraries Provided by this Package

This package includes:

3 Known Limitations

The parser does not recognize the C preprocessor. I may attempt to implement the preprocessor in the future, but there’s no guarantee at this point.

The grammar does not support any extensions for GCC, MSVC, or any other specific C implementations. I intend to add support for these extensions on a by-need basis. Specific requests (as well as patches) are welcome.

External compilation is currently limited to GCC. I intend to add support for additional compilers on a by-need basis; patches are welcome.

4 Feedback and Bug Reports

Before sending feedback or bug reports, please consult the current set of registered issues. If you cannot find your issue there, feel free to file a new bug report in the online issue database.

Any other feedback may be emailed to me, Dave Herman, at dherman@ccs.neu.edu.

5 History