Journal Articles

CVu Journal Vol 12, #4 - Jul 2000 + Letters to the Editor
Browse in : All > Journals > CVu > 124 (22)
All > Journal Columns > LettersEditor (132)
Any of these categories - All of these categories

Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.

Title: The Wall

Author: Administrator

Date: 08 July 2000 13:15:38 +01:00 or Sat, 08 July 2000 13:15:38 +01:00

Summary: 

Body: 

I did not know…

Dear Francis,

This is an interesting one, I have just found this out whilst using Visual Studio 6 SP3.

int main() {
  int iVal;
  iVal = 1; 
  {
    printf("iVal == %d\n", iVal);
    int iVal = 2;
    printf("iVal == %d\n", iVal);
  }
  printf("iVal == %d\n", iVal);
  return 0;
}

Output is:

1
2
1

I was not actually aware that you could do this in C++, and just spotted it as a typo during a code review, declaring a duplicate variable appears to hide the outer scope declaration, could be nasty. I would expect a warning to be raised but Visual Studio does not display any warning at all even with the warning level set to 4, I trust this is not right! :-)

NB. I have gone through the list of warnings VS uses and there does not appear to be any applicable one listed, this behaviour also happens in C and C++ mode.

Darren Jefford

The code you provide is faultless C++ though a C compiler should have thrown it out because a declaration after an executable statement at block scope. Note the past tense, the new C standard allows late declarations.

This hiding rule has always been the case. Reusing an identifier in an inner scope hides the one in the outer scope. C++ provides mechanisms for referring to the hidden name if that was declared at global, namespace or class scope.

In strictly conforming mode a C++ compiler must not issue a diagnostic (though it is up to the implementers to determine whether a warning constitutes a diagnostic). However, I would expect a quality compiler to issue a warning for declaring a name that had already been used in the current scope to refer to something in an outer scope. FG.

Notes: 

More fields may be available via dynamicdata ..