Task: Come up with an extension to the C programming language. Provide a clear description of the extension, and a code sample that clearly shows what the extension is intended to do.
Prize: (Winning criteria are not specified.) The winner will have his extension featured in the C11 language standard.
My entry: ... Sorry, I think C is perfect in every way already.
Name:
Anonymous2010-07-18 21:06
My entry:
Meta-C (That name is probably already taken)
A built-in scripting language that runs, effectively, as a precompile step. In otherwords
myfile.metac -> script parser -> myfile.c -> normal C compiler -> etc...
The scripting language might be Perl-like or Python-like, I don't know, but it just needs to be something modern with nice regular expression support.
The script delimiters are /@ and @/.
Example of what you could do:
myfile.metac
#include <stdio.h>
int main(int, char**)
{
/@
# (Assuming perl is the embedded language)
my $n = 5;
foreach my $i (1 .. $n)
{
@/
printf("this line prints /@$n@/ times, this is time number /@$i@/\n");
/@
}
@/
return 0;
}
The script parser would expand that to
myfile.c
#include <stdio.h>
int main(int, char**)
{
printf("this line prints 5 times, this is time number 1\n");
return 0;
}
This is a pretty trivial example but the concept is very powerful. You implement most of C++ manually in this way, since nearly everything C++ adds to C is just compile-time crap. But the bonus would be that you would be in control of how things behave, instead of the C++ compiler.