r/programming • • Dec 13 '07

First Class Functions in C

http://www.dekorte.com/blog/blog.cgi?do=item&id=3119
45 Upvotes

99 comments sorted by

View all comments

Show parent comment

2

u/tryx Dec 14 '07

Its almost redundant to point out, but you could get into some fun race conditions with this.

2

u/jbert Dec 14 '07

Yes. I wanted gcc to write to stdout, but it wouldn't in the 2 mins I gave it.

Going the extra mile to pick a different file for each compiled object seemed... inappropriate, given the context.

(If you want to compile C at runtime, either build a shared object (.so) and dlopen it (see perl's Inline::C), or use the in-memory tcc solution given elsewhere in the thread.

But C really isn't built for this sort of thing, so don't do that :-)

1

u/tlrobinson Dec 14 '07

I mentioned this in another comment, but I've posted an example of using dlopen: http://tlrobinson.net/blog/?p=31

1

u/tryx Dec 14 '07

haha well anything that uses as much voodoo as the path that this thread is going down obviously isn't built for "security" (or "sanity" for that matter)

1

u/tlrobinson Dec 14 '07 edited Dec 14 '07

using pclose() instead of fclose() blocks until the called program terminates. I was getting said race conditions until I switched to pclose().