News for hackers. Stuff that matters.
Re:Abusing the C Compiler by acqq on Wednesday September 08, 2010 @06:40AM (#1671491)
Hardly abusing or original, generating small chunks of code and invoking C compiler on each of these is how GNU autoconf works (and the reason it works slow, too!)
Re:Abusing the C Compiler by wingo on Wednesday September 08, 2010 @07:10AM (#1671520)
An interesting parallel. I guess the novelty is that there is no intermediate expanded file -- no config.h, etc.
Re:Abusing the C Compiler by tedunangst on Wednesday September 08, 2010 @02:27PM (#1672843)
What would you call tmp.c, a.out, tmp.txt and so on if not intermediate files?
Re:Abusing the C Compiler by mfukar on Wednesday September 08, 2010 @09:01AM (#1671687)
I don't see a single sentence in the article that implies this.
Re:Abusing the C Compiler by wingo on Wednesday September 08, 2010 @09:22AM (#1671740)
Not sure what you mean here; the autoconf analogy came from the grandparent.

If you are under the impression that an intermediate expanded file is produced, then you misunderstand how Lisp macros work.

Re:Abusing the C Compiler by acqq on Wednesday September 08, 2010 @09:42AM (#1671781)
If I understood correctly, here the Lisp code generates the C code which generates the small chunks of Lisp code which are then compiled. But I don't understand what you mean under "intermediate expanded file." In autoconf the config.h is the final resulting chunk that is used in the final compilation (somewhat in parallel to Lisp chunks generated by the C)." What's your take?
Re:Abusing the C Compiler by mfukar on Wednesday September 08, 2010 @01:14PM (#1672536)
I'd like to point you to the 2008 paper by Felix Klock [1], or perhaps the more easily digestible presentation [2], where you will find (slide 39-47) the description of the inner workings of procedural macros like define-c-info, where it's explicitly stated that an intermediate C program is generated, compiled & executed to get the desired result(s).

This is not groundbreaking per se, but it is certainly a smart compile-time tactic of interfacing with a C ABI.

[1] http://www.ccs.neu.edu/home/pnkfelix/Published/klock-ffi-sch... [2] http://www.ccs.neu.edu/home/pnkfelix/Published/klock-ffi-sch...

Re:Abusing the C Compiler by wingo on Wednesday September 08, 2010 @01:38PM (#1672648)
I agree, that is a great paper. It's the one I linked to in my article :)
Re:Abusing the C Compiler by mfukar on Wednesday September 08, 2010 @03:37PM (#1673142)
I was specifically referring to the usage of intermediate files...I think I assumed too much, since obviously you must have a very different view of what consists an intermediate file than I do. Would you care to elaborate?
Re:Abusing the C Compiler by wingo on Wednesday September 08, 2010 @04:27PM (#1673360)
I don't want to get too bogged down here, but sure:

When you use autoconf, you typically run configure, then you're left with a config.h, which then parameterizes later builds.

On the other hand, when you evaluate the the definition of dirent->name, no intermediate file is left behind.

Of course in both cases you make temporary C files, but they are ephemeral. The difference is that in the first case you are generating files for inclusion in a later phase, and in the second you are effectively extending your scheme compiler with a c compiler.

The surprising about this code from a Scheme programmer's POV is that usually macros are about rewriting Scheme source using Scheme. In this case the macro generates C source, forks to compile and run it, and munges the result into the resulting text.

But sure, I can see that from a certain point of view, autoconf and scheme macros can do similar things :)

Re:Abusing the C Compiler by mfukar on Thursday September 09, 2010 @05:23AM (#1674856)
I see your point, but the fact remains that the underlying technique is just the same. The difference on whether intermediate files are used further down the build process seems somewhat irrelevant.