* Andrew Haley <aph@xxxxxxxxxx> wrote: Hi, > Yes. For example, have a look at expand_builtin_fprintf() and > expand_builtin_strcpy() in > http://gcc.gnu.org/viewcvs/trunk/gcc/builtins.c?view=markup Thx. I'm quite new to gcc internals, so i'd appreciate a bit more help. Is it possible to inject some C-code instead of the original function call ? For example: char foo[1024]; snprintf(foo, sizeof(foo), "/tmp/%s%d.tmp", prefix, id); Would inject something like: char foo[1024] = "/tmp/"; { long __bufmax; // remaining space in buffer char* __bufptr; // current buffer position // skip over the already initialized head __bufmax = sizeof(foo)-6; __bufptr = &foo[5]; // the %s -> prefix part { long __len__prefix = strlen(prefix); // copy the parameter "prefix" if (__bufmax > __len_prefix) { memcpy(bufptr, prefix, __len_prefix); bufptr += __len_prefix; bufmax -= __len_prefix; } else { memcpy(bufptr, prefix, __bufmax); goto __out_terminate; } } // generate the %d -> id { struct __itoa_buf __fmt_d_id = __itoa_std(id); if (__bufmax > __itoa_buf.len) { memcpy(bufptr, __itoa_buf.buf, __itoa_buf.len); bufptr += __itoa_buf.len; bufmax -= __itoa_buf.len; } else { memcpy(bufptr, __itao_buf.buf, __bufmax); goto __out_terminate; } } // the suffix is short enough to be added char by char if (__bufmax) { *__bufptr = '.'; __bufptr++; __bufmax--; } else goto __out_terminate; if (__bufmax) { *__bufptr = 't'; __bufptr++; __bufmax--; } else goto __out_terminate; if (__bufmax) { *__bufptr = 'm'; __bufptr++; __bufmax--; } else goto __out_terminate; if (__bufmax) { *__bufptr = 'p'; __bufptr++; __bufmax--; } __out_terminate: *bufptr = 0; } And the whole thing goes through the compiler/optimizer again. cu -- --------------------------------------------------------------------- Enrico Weigelt == metux IT service - http://www.metux.de/ --------------------------------------------------------------------- Please visit the OpenSource QM Taskforce: http://wiki.metux.de/public/OpenSource_QM_Taskforce Patches / Fixes for a lot dozens of packages in dozens of versions: http://patches.metux.de/ ---------------------------------------------------------------------