Pragma

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Imposter
    New Member
    • Dec 2011
    • 3

    Pragma

    How can i use a pragma directive in order to show warning by compiler when a variable is declared twice.. That is

    class a
    {
    int b;
    void f()
    {
    int b;
    }
    };

    although it is getting compiled without warning.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Your variable is not defined twice.

    There are two variables. They have the same name which is OK because the scope is different.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      pragmas are entirely compiler dependent, you only have what your compiler provides.

      However in general no compiler provides a way to add warnings. If the compiler is able to do it it will already be a part of the compiler.

      As weaknessforcats says your problem is that you have defined two variables at different scopes but because they have the same name the one in a::f hides the member declaration in a.

      Static analysis tools, such as PCLint will pick up this sort of error.

      Comment

      Working...