Reference static const variables declared in namespace - doxygen

I am fleshing out the doxygen documentation for my modules and came across a strange problem. When referencing variables located in a namespace autolinking does not work. Here is a snippet:
namespace isa {
const double H_max= 10000; //!< #brief Maximum altitude in meters.
//! #brief Calculate air densitity at altitude \a H.
//! #throw argument_exception when \a H exceeds ::H_max.
double rho(double H);
} // namespace isa
I would expect doxygen to put a link to H_max at the exception description of function rho(double) to direct the reader to the constant. But it only does if I leave away the namespace, otherwise autolinking does not work.
What am I doing wrong?
Thanks in advance.

OK, so the problem here is not a doxygen wrong behavior, but a misunderstanding on how the global namespace prefix :: works.
::H_max identifies a symbol defined in the global namespace, that is, out of any namespace. I'm afraid - correct me if I'm wrong - that you where expecting it to behave as the parent directory .. identifier.
When doxygen processes the code snippet you provided, it doesn't link ::H_max in the exception description because it cannot find a H_max variable in the global namespace. If you remove the double colon prefix, it should provide a link to isa::H_max.

Related

Doxygen : error variable seen as function

I have in a function the following variable :
97
98 UINT8 Reponse;
99 static UINT8 Initialisation = 0;
100 static DWORD StartTime = 0; //
Initialisation is also the name of one function :
void Initialisation(void)
When I clic on the hyperlink on Initialisation line 99, the block of function void Initialisation(void) is oppened.
Did any of you have an idea of what is appening ?
Thanks you for your help
Jean-Marie
See doxygen's Known Problems:
Not all names in code fragments that are included in the documentation are replaced by links (for instance when using SOURCE_BROWSER = YES) and links to overloaded members may point to the wrong member. This also holds for the "Referenced by" list that is generated for each function.
For a part this is because the code parser isn't smart enough at the moment. I'll try to improve this in the future. But even with these improvements not everything can be properly linked to the corresponding documentation, because of possible ambiguities or lack of information about the context in which the code fragment is found.
and
Doxygen does not work properly if there are multiple classes, structs or unions with the same name in your code. It should not crash however, rather it should ignore all of the classes with the same name except one.

Doxygen not reading code guarded with macro

I am using doxygen to generate html help for our C++ API.
There are parts which are enabled/disabled in code such as
#ifdef EXPERIMENTAL_FEATURE1
class Experimental1
{
...
}
#endif
#ifdef EXPERIMENTAL_FEATURE2
class Experimental2
{
...
}
#endif
I set my doxygen PREDEFINED as follows:
PREDEFINED = EXPERIMENTAL_FEATURE1 EXPERIMENTAL_FEATURE2
This however doesn't cause doxygen to extract doc. for these classes. Log shows that doxygen reads the files.
Is the syntax for PREDEFINED correct (separated by space and without =)?
How can I debug this?
Have a look into the doxygen manual:
http://www.doxygen.nl/manual/preprocessing.html
The typical syntax is:
PREDEFINED = "name1=value1" \
"name2=value2" \
"name3=value3"
In more detail the manual says:
The argument of the tag is a list of macros of the
form: name or name=definition (no spaces). If the definition and the "=" are omitted, "=1" is assumed.
To prevent a macro definition from being undefined via #undef or recursively expanded use the := operator
instead of the = operator.
If you have no value you can simply write "name" - so your example should work.
Make sure that the following settings are correct within your doxyfile:
HIDE_UNDOC_CLASSES=NO
EXTRACT_ALL=YES
EXTRACT_LOCAL_CLASSES=YES
Otherwise classes aren't put into the documentation.
Also make sure ENABLE_PREPROCESSING is set to YES.
If all this doesn't help please post a minimal example that reproduces the problem.

Replace a macro with a different definition in Eclipse?

I'm working on a project which defines globals like this:
// Define an correctly-sized array of pointers to avoid static initialization.
// Use an array of pointers instead of an array of char in case there is some alignment issue.
#define DEFINE_GLOBAL(type, name, ...) \
void * name[(sizeof(type) + sizeof(void *) - 1) / sizeof(void *)];
Which apparently works fine, but causes Eclipse to show every single usage of one of these globals as an error.
I would prefer that it be this:
#define DEFINE_GLOBAL(type, name, ...) \
type name;
But I can't change this file, so is there a way to tell Eclipse to pretend that that's the macro's definition?
If you #define the preferred definition after the initial (unwanted) definition, Eclipse seems to use the most recent definition when it does the dynamic macro expansion.
Thus, if you re-#define the macro in the file you are editing, this may solve your problem.
Granted that this is a kludge and may cause unforeseen problems, it may work for your implementation.

What does `m_` variable prefix mean?

I often see m_ prefix used for variables (m_World,m_Sprites,...) in tutorials, examples and other code mainly related to game development.
Why do people add prefix m_ to variables?
This is typical programming practice for defining variables that are member variables. So when you're using them later, you don't need to see where they're defined to know their scope. This is also great if you already know the scope and you're using something like intelliSense, you can start with m_ and a list of all your member variables are shown. Part of Hungarian notation, see the part about scope in the examples here.
In Clean Code: A Handbook of Agile Software Craftsmanship there is an explicit recommendation against the usage of this prefix:
You also don't need to prefix member variables with m_ anymore. Your classes and functions should be small enough that you don't need them.
There is also an example (C# code) of this:
Bad practice:
public class Part
{
private String m_dsc; // The textual description
void SetName(string name)
{
m_dsc = name;
}
}
Good practice:
public class Part
{
private String description;
void SetDescription(string description)
{
this.description = description;
}
}
We count with language constructs to refer to member variables in the case of explicitly ambiguity (i.e., description member and description parameter): this.
It is common practice in C++. This is because in C++ you can't have same name for the member function and member variable, and getter functions are often named without "get" prefix.
class Person
{
public:
std::string name() const;
private:
std::string name; // This would lead to a compilation error.
std::string m_name; // OK.
};
main.cpp:9:19: error: duplicate member 'name'
std::string name;
^
main.cpp:6:19: note: previous declaration is here
std::string name() const;
^
1 error generated.
http://coliru.stacked-crooked.com/a/f38e7dbb047687ad
"m_" states for the "member". Prefix "_" is also common.
You shouldn't use it in programming languages that solve this problem by using different conventions/grammar.
The m_ prefix is often used for member variables - I think its main advantage is that it helps create a clear distinction between a public property and the private member variable backing it:
int m_something
public int Something => this.m_something;
It can help to have a consistent naming convention for backing variables, and the m_ prefix is one way of doing that - one that works in case-insensitive languages.
How useful this is depends on the languages and the tools that you're using. Modern IDEs with strong refactor tools and intellisense have less need for conventions like this, and it's certainly not the only way of doing this, but it's worth being aware of the practice in any case.
As stated in the other answers, m_ prefix is used to indicate that a variable is a class member. This is different from Hungarian notation because it doesn't indicate the type of the variable but its context.
I use m_ in C++ but not in some other languages where 'this' or 'self' is compulsory. I don't like to see 'this->' used with C++ because it clutters the code.
Another answer says m_dsc is "bad practice" and 'description;' is "good practice" but this is a red herring because the problem there is the abbreviation.
Another answer says typing this pops up IntelliSense but any good IDE will have a hotkey to pop up IntelliSense for the current class members.
Lockheed Martin uses a 3-prefix naming scheme which was wonderful to work with, especially when reading others' code.
Scope Reference Type(*Case-by-Case) Type
member m pointer p integer n
argument a reference r short n
local l float f
double f
boolean b
So...
int A::methodCall(float af_Argument1, int* apn_Arg2)
{
lpn_Temp = apn_Arg2;
mpf_Oops = lpn_Temp; // Here I can see I made a mistake, I should not assign an int* to a float*
}
Take it for what's it worth.
As stated in many other responses, m_ is a prefix that denotes member variables. It is/was commonly used in the C++ world and propagated to other languages too, including Java.
In a modern IDE it is completely redundant as the syntax highlighting makes it evident which variables are local and which ones are members. However, by the time syntax highlighting appeared in the late 90s, the convention had been around for many years and was firmly set (at least in the C++ world).
I do not know which tutorials you are referring to, but I will guess that they are using the convention due to one of two factors:
They are C++ tutorials, written by people used to the m_ convention, and/or...
They write code in plain (monospaced) text, without syntax highlighting, so the m_ convention is useful to make the examples clearer.
Others have mentioned that it means a class member. Qt is a popular c++ Framework that uses this notation so alot of C++ GUI tutorial use m_. You can see almost all their examples use m_ for class members. Personally, I use m_ as it is shorter than this-> and feels compact.
To complete the current answers and as the question is not language specific, some C-project use the prefix m_ to define global variables that are specific to a file - and g_ for global variables that have a scoped larger than the file they are defined.
In this case global variables defined with prefix m_ should be defined as static.
See EDK2 (a UEFI Open-Source implementation) coding convention for an example of project using this convention.
One argument that I haven't seen yet is that a prefix such as m_ can be used to prevent name clashing with #define'd macro's.
Regex search for #define [a-z][A-Za-z0-9_]*[^(] in /usr/include/term.h from curses/ncurses.

what's handle and isa

I need an explanation with a simple examples about the following concepts:
'handle' function
#
+
isa
These are part of API that mathworks has devised.
A folder whose name begins with an # sign contains the definition of Matlab objects.
The folders with the + sign are similar, but they are used to define a "package" or namespace. These are hard to give an example of, but I would recommend looking at the help like gnovice says and looking through your matlab install folders for examples.
The isa() command takes an object and a string and tells you if the object is of the class descibed by the string.
A function handle, is just like a function pointer. You can pass the function handle around if you assign the function to a variable like:
myFuncRef = #isempty
Now you have a reference to the isempty() function which can be use like so:
myFuncRef(somevar)