问题
I came across some standalone code without headers. I believe it to be straight C/C++, but am not sure. If so, what does the "CLASS" in the following mean? I know it's not a class declaration or definition. Is this a method of a class named "CLASS"?
void CLASS functionName(){
//
//
//
}
I'm used to seeing <returnType> <functionName>() {...}
, but not the above. Am I forgetting something? (Pardon me, as I've been in JS and Objective-C lately.)
回答1:
Although it's not common AFAIK, it could be that CLASS is a macro as below. Since its name is CLASS
, I would say it's more likely that it's a macro for a class or namespace.
1. Class Name
class A
{
void functionName();
};
#define CLASS A::
void CLASS functionName()
{}
2. Namespace
namespace A
{
void functionName();
};
#define CLASS A::
void CLASS functionName()
{}
3. Calling Convertion
// or __cdecl, etc.
define CLASS __stdcall
4. Others
There could be others (e.g., a macro for a pointer) which are syntactically correct, but they're less likely in your case. Or it could simply be a comment, as Hostile points out below.
回答2:
This is definitely not standard C or C++, as there's only a few things that could legally go in-between the void
and the function name (a star, for example, to make the return type void *
). This is probably a macro that's being used by some compiler extension or external tool. Without more information about where you found this code I don't think I can offer more than that; where did you find this?
回答3:
I used Google's Code Search (which can come in handy sometimes) and found an instance of this in "rawtherapee":
http://codesearch.google.com/#search/&q=%22void%20CLASS%22&type=cs&exact_package=http://rawtherapee.googlecode.com/hg/
Not surprisingly, the definition is a macro (there's little else it could be), but it's just an empty #define
. The definition is explained here:
All global variables are defined here, and all functions that access them are prefixed with "CLASS". Note that a thread-safe C++ class cannot have non-const static local variables.
At least in that project, it's basically being used for documentation purposes, and purposefully is stripped out by the preprocessor. I've seen this done marking pointer parameters as IN
or OUT
before, sort of like in MIDL.
@EricZ has made a good inventory of possible uses. Yet I am fairly sure this is what you're seeing, because of the authorship and project name overlap between Rawness (your case) and Rawtherapee...
来源:https://stackoverflow.com/questions/7088292/c-syntax-void-class-functionname