Even though it is its own project, most folks use it alongside GCC.
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Calli...
For Partial Evaluation, you must generate a "residual" version of the original program by specialization where all static data is already bound and evaluated.
Simplest example would be compiling in configuration parameters, so a specific code-path is preselected before runtime. Another classic example would be C++ template meta-programming where that part of the program is not evaluated at runtime.
I first came to know of these techniques from the classic Generative Programming: Methods, Tools, and Applications by Krzysztof Czarnecki and Ulrich W. Eisenecker which is still relevant today.
Checking with Google, it seems GCC does not have a separate partial evaluator but one can use coding techniques+aggressive optimization switches to approximate it. For separate "Futamura Projection" like partial evaluators there seem to be C-Mix/LLPE etc.
Partial Evaluation and Automatic Program Generation by Neil Jones et al. - https://web.archive.org/web/20071012081310/http://www.itu.dk...
miniprintf(char fmt[], int val[])
{
int i = 0;
while( *fmt != '\0' ) {
if( *fmt != '%' )
putchar(*fmt);
else
switch(*++fmt) {
case 'd' : putint(val[i++]); break;
case '%' : putchar('%'); break;
default : prterror(*fmt); break;
}
fmt++;
}
}
If the static string was "%", the else branch would move past the end of the string. Assuming prterror doesn't crash the program, this reads out-of-bounds, right?In your example, "%" would cause switch ('\0') which would fall in the default case.
The function should probably return on error.
Edit: I guess it may not technically be a bug as it's just a small function, but using a single % instead of %% (which is what printf expects) would be a format error, hence prterror()
If it's not a fatal error, then yes it would continue past the end of the string
Wait - does prterror cause the program to exit? It's not defined, so maybe the program does terminate, maybe it doesn't.
That's a bit of an ontological conundrum: does a bug exist when it never occurs? I'd say there is a bug, unless the function has a contract that guarantees there's always a character following every first % (and something about the length of the second array, of course). So I see a bug as something wrong with the design.
But if you see a bug as something purely pertaining to runtime, then you are right. But when is "never"? If it is proven not to occur, or is it enough that the circumstances in which it is used just happen no to trigger it? (Note that in the last phrase, "it" refers to the bug, and implies it exists...)
BTW, in the example, the partial evaluator could prove the presence or absence of bugs.
It is used extensively in STL algorithms so that raw pointers and container.end() behave the same.