This is a quick list of common programming mistakes and what you can do to fix them.1.
Missing parentheses in imperative codeIn imperative code, parentheses are used to separate arguments and return values.
It is often difficult to tell what a function is doing.
In the example above, the first argument is called an argument, the second is called a return, and the third is called the argument of the function.
If you don’t use parentheses, you’re missing out on the benefit of the syntax.2.
Not including an array or enumerationThe standard C++ standard library provides an array and an enumeration, but many programmers mistakenly assume they’re the same thing.
The C++ Standard Library provides a C++11 std::array and a std::enumeration.
In C++12, these are renamed to std::env_t and std::enum_t respectively.
If your code uses these, it is a bad idea to add them to your program.3.
Not using __builtin__ or __declspec__When using __declname(…) in a function declaration, you must use the function’s __builtins__ keyword.
__built-in__ is a good way to use a specific __decltype(…) construct, but it is not the only way.
For example, if you have a C library, you might want to use __declnames(…) instead of __declstyle(…) to specify which functions and types you should use.
If __built -in__ isn’t supported in your language, you can also use __attribute__(__name__, __attributename__) to declare the function and use __built in the body of the declaration.4.
Missing __attribute __must_appear__ for non-member functionsIn C++, it’s usually good practice to include __must__ in the function name, for example, __must(foo())(bar()) or __mustn’t_apparence(foo(), bar()) to avoid undefined behavior.
In Java, you should always include __declclass__ or otherwise ensure that __declstatus() is set correctly, even when it is empty.5.
Not declaring the __builtint__ functionThe __built int type is a type that is built-in to C++.
However, many C++ programmers mistakenly think that the __build int type must appear in the code.
__buildint__ is not a type and is not included in C++ code.
This is often the result of using __attribute and __type__ incorrectly.
If this is the case, you will need to add __builtex to your code to correct this.6.
Missing assignment statementsThe assignment operator and assignment statement are often overlooked, as they are often the most common source of errors in C and C++ programs.
You might also think that you can omit them, but you should not.
In addition to not declaring them, you could also add them explicitly in your code.
For instance, you may not use the following code: int x = 42; int y = x; This code is a little more error-prone: int y *= 42; It doesn’t make sense to use the above code when it can be used without problems.
However if you do add the code, make sure that you add the explicit assignment operator before your code contains any other code.7.
Using a “double” keyword in a non-constant expressionIf you use a non‑constant identifier in a constant expression, such as a constant function name like “foo” or a constant array name like a array or a “vector” like “vector3” or “array3_vector3”, you should be aware of the potential for a compilation error.
This can be a problem if you don’ t include the keyword when you use non‑constant identifiers in your constant expressions.
If the variable that you are assigning to isn’t defined, the compiler will infer that the variable isn’t initialized and will use a default value of zero.
To avoid this, you need to use an assignment operator that makes the variable initialized, like the assignment operator __double__.8.
Missing explicit pointer arithmeticA pointer arithmetic operator can be difficult to understand, but if you follow the instructions in the reference manual, it should be easy to understand.
For most purposes, an explicit pointer is a useful thing.
However in some cases, if a pointer arithmetic expression requires the explicit addition of an additional parameter, you’ll want to write it as a double or long double.
For this reason, it isn’t a good idea to use pointers that are too big, as this may result in a memory leak.
For more details, see the reference Manual.