duplicate variable names seperated by scope
-
I was once maintaining some odd looking code that had the (no joke) the following pattern:
int variable; class CSomething { public: int variable; void Func(int variable) { // do something { int variable; // do something where the bug I was trouble shooting was located } }; };
Count them: FOUR declarations of the same variable name (and type) in the same file! 1) In the global scope 2) As a member var 3) as a function parameter 4) declared IN SIDE the function that has the identical named param Yes, it was legal - but it didn't make it right.[ Jason De Arte | Toy Maker | 1001010.com ]
-
I was once maintaining some odd looking code that had the (no joke) the following pattern:
int variable; class CSomething { public: int variable; void Func(int variable) { // do something { int variable; // do something where the bug I was trouble shooting was located } }; };
Count them: FOUR declarations of the same variable name (and type) in the same file! 1) In the global scope 2) As a member var 3) as a function parameter 4) declared IN SIDE the function that has the identical named param Yes, it was legal - but it didn't make it right.[ Jason De Arte | Toy Maker | 1001010.com ]
Makes me remind of the last programming exams i took... They make you go insane with a snippet 10 times difficult than the above, then they ask you "WTF does var on line x refer to, which is its value?" Someone just never learns ;)