Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by ikegami (Pope)
on Nov 25, 2004 at 19:00 UTC ( #410449=note: print w/ replies, xml ) Need Help??


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

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'


Comment on Re^4: Pearls (not really) of Perl programming
Select or Download Code
Re^5: Pearls (not really) of Perl programming
by Anonymous Monk on Nov 26, 2004 at 23:25 UTC
    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
Node Status?
node history
Node Type: note [id://410449]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2014-08-31 00:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls