Using C macros without massive rewrites

Alex Rønne Petersen alex at lycus.org
Mon Jun 11 21:15:38 PDT 2012


On 12-06-2012 04:20, Charles McAnany wrote:
> Hi, all. I'm studying Kerrisk's The Linux Programming Interface for fun.
> The book is written in C, and I thought it would be fun to do the
> exercises in D. My problem is that I'm doing things like
> #include <sys/types.h>
> in my C code and that loads oodles of macros like ssize_t, O_RDONLY,
> EXIT_SUCCESS, etc.
>
> I don't mind writing .di files for the occasional function I use, but
> tracking down every last typedef and #define is going to be a hassle.
> The functions aren't bad because you can just make a C file that
> #includes all the libraries you want, cc it to lib.o then write a .di
> that uses the functions you want from that mammoth.
> Extracting the #defines and typedefs from stdlib.h (and everything it
> includes) sounds, uh, daunting. (this suspicion is corroborated by
> Deimos, which has no commits to the libc repository)
>
> I was thinking it wouldn't be too bad if I could write a .c file that
> somehow conveniently boxes up the relevant information for a .di file to
> extract it, but I'm at a loss for where to go with this.
>
> Alternatively, I could maybe run the .di file through gcc for
> preprocessing only and hope that I don't confuse its lexer.
>
> Has anyone here had any experience with these things?

The core.stdc.* package has modules for all C99 headers and for most 
system headers of each platform (Linux, OS X, FreeBSD, Windows, etc).

And in general, there's no good way to automatically translate macros to D.

-- 
Alex Rønne Petersen
alex at lycus.org
http://lycus.org


More information about the Digitalmars-d-learn mailing list