Why does GCC not warn for unreachable code?

GCC 4.4 will give you a warning. In the later versions of GCC, this feature (-Wunreachable-code) has been removed. See Re: gcc -Wunreachable-code option The -Wunreachable-code has been removed, because it was unstable: it relied on the optimizer, and so different versions of gcc would warn about different code. The compiler still accepts and ignores … Read more

When should I use static methods in a class and what are the benefits?

Your description of a static variable is more fitting to that found in C. The concept of a static variable in Object Oriented terms is conceptually different. I’m drawing from Java experience here. Static methods and fields are useful when they conceptually don’t belong to an instance of something. Consider a Math class that contains … Read more

What is the use of static variable in C#? When to use it? Why can’t I declare the static variable inside method?

A static variable shares the value of it among all instances of the class. Example without declaring it static: public class Variable { public int i = 5; public void test() { i = i + 5; Console.WriteLine(i); } } public class Exercise { static void Main() { Variable var = new Variable(); var.test(); Variable … Read more

Superiority of unnamed namespace over static?

You’re basically referring to the section ยง7.3.1.1/2 from the C++03 Standard, The use of the static keyword is deprecated when declaring objects in a namespace scope; the unnamed-namespace provides a superior alternative. Note that this paragraph was already removed in C++11. static functions are per standard no longer deprecated! Nonetheless, unnamed namespace‘s are superior to … Read more