digitalmars.D.learn - __func__
- Zarathustra (4/4) Oct 04 2009 Does in D exist something like __func__?
- Jarrett Billingsley (35/39) Oct 04 2009 No.
Does in D exist something like __func__? For example in gcc: int main(){ printf("%s", __func__); ...} returns "main".
Oct 04 2009
On Sun, Oct 4, 2009 at 5:12 PM, Zarathustra <adam.chrapkowski gmail.com> wrote:Does in D exist something like __func__? For example in gcc: int main(){ printf("%s", __func__); ...} returns "main".No. There is a ridiculous workaround though. // Parsing mangles for fun and profit. char[] _getJustName(char[] mangle) { size_t idx = 1; size_t start = idx; size_t len = 0; while(idx < mangle.length && mangle[idx] >= '0' && mangle[idx] <= '9') { int size = mangle[idx++] - '0'; while(mangle[idx] >= '0' && mangle[idx] <= '9') size = (size * 10) + (mangle[idx++] - '0'); start = idx; len = size; idx += size; } if(start < mangle.length) return mangle[start .. start + len]; else return ""; } const char[] FuncNameMix = "static if(!is(typeof(__FUNCTION__))) {" "struct __FUNCTION {} const char[] __FUNCTION__ = _getJustName(" "__FUNCTION.mangleof); }"; Now you can use: import std.stdio; void main() { mixin(FuncNameMix); writefln("%s", __FUNCTION__); } You just mix FuncNameMix into any function where you want to use __FUNCTION__.
Oct 04 2009