Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Pearls (not really) of Perl programming

by Anonymous Monk
on Nov 25, 2004 at 18:11 UTC ( [id://410439]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Pearls (not really) of Perl programming
in thread Pearls (not really) of Perl programming

Actually, I believe that the C++ behaviour you pointed out is an MSVC glitch.
for(int i = 0; ;) { }
... should have "i" visible only inside the for loop. I think gcc actually does this properly, as does MSVC .NET. ... unless I'm horribly wrong?

Replies are listed 'Best First'.
Re^4: Pearls (not really) of Perl programming
by ikegami (Patriarch) on Nov 25, 2004 at 19:00 UTC

    Close... VC++ .NET allows it, gcc 2.95.4 forbids it.

    a.cpp

    #include <stdio.h> int main() { for (int i=0; i<5; i++) { printf("%d\n", i); } printf("%d\n", i); return 0; }

    VC++ .NET

    >cl a.cpp Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for +80x86 Copyright (C) Microsoft Corporation 1984-2002. All rights reserved. a.cpp Microsoft (R) Incremental Linker Version 7.10.3077 Copyright (C) Microsoft Corporation. All rights reserved. /out:a.exe a.obj >a 0 1 2 3 4 5

    gcc 2.95.4

    $ gcc a.cpp -o a a.cpp: In function `int main()': a.cpp:9: name lookup of `i' changed for new ANSI `for' scoping a.cpp:5: using obsolete binding at `i'
      And gcc points out why. Because it was allowed at one time (in C++) it was introduced into C. Then the C++ guys discovered that it was inconsistent with if() (where it was forbidden from day 1) and removed it. ANSI followed (much) later in C. MS wants to be 'helpful' and allows it. But I would want to know which i is used if the outer block has one too. I would think MS to try to combine the old and new behavior in some MS-unique style and make a mess of it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://410439]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found