Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature : OF_FUNC_NAME #1996

Open
elliotwoods opened this issue Apr 7, 2013 · 10 comments
Open

Feature : OF_FUNC_NAME #1996

elliotwoods opened this issue Apr 7, 2013 · 10 comments

Comments

@elliotwoods
Copy link
Contributor

something like:

#ifndef __func__ //(maybe more platform-safe)
#define OF_FUNC_NAME __FUNCTION__
#else
#define OF_FUNC_NAME __func__
#endif

in ofConstants.h

basically so people can get the current function name for errors, etc in a platform agnostic way.

elliot

(Edit : OF_FUNC became OF_FUNC_NAME)

@kylemcdonald
Copy link
Contributor

can you provide a bit more context? i haven't used this strategy before. when is it most useful?

@elliotwoods
Copy link
Contributor Author

it basically means you can do something like:

void wildClass::doSomethingDangerous() {
    if (!trySomethingAndReturnTrueIfSuccessful()) {
        ofLogError(OF_FUNC_NAME) << "disaster!";
    }
} 

and you'd get

[error wildClass::doSomethingDangerous] disaster!

(can't remember if that's exactly right for oF error output formatting)

@elliotwoods
Copy link
Contributor Author

(essentially it makes sense on gcc to just use __func__ for this purpose, but it's not compatible with visual c++)

@bilderbuchi
Copy link
Member

relevant discussion: #985

@elliotwoods
Copy link
Contributor Author

good spot! the 2 issues are compatible (the other could then possible use OF_FUNC_NAME)

anybody can see this having enough use to include in core?

@bilderbuchi
Copy link
Member

I think it could be useful, and it's pretty simple. Does that warrant inclusion in the core? that's not my call I think.
The discussion in #985 is worth a read (again), debating the best ways to implement what you want (i.e. more information in ofLog).

Another point: doesn't __func__/__FUNCTION__ only give you the function name? so in your above example you would only get doSomethingDangerous, not wildClass::doSomethingDangerous which severely limits the proposed macro's use when the class method names are called, e.g. setup(). I'm not sure though, and haven't tried, but gcc docs seem to say so.
Also, see this pretty detailed SO answer for some background.

@bilderbuchi
Copy link
Member

also, check out https://github.com/gameoverhack/ofxLogger

@underdoeg
Copy link
Contributor

I think that could be useful. Another usage example & implementation: https://github.com/damiannz/ofxProfile/blob/master/src/ofxProfile.h

@ofTheo
Copy link
Member

ofTheo commented Jul 7, 2013

I have no problem adding this in.
Then we could do a big push on all the logging calls to use OF_FUNC_NAME

@bilderbuchi
Copy link
Member

we should definitely take some wisdom from #985 when we do this, there's lots of groundwork already done, especially in @gameoverhack's ofxLogger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants