Strange VC++ 2003 behaviour

This is a discussion on Strange VC++ 2003 behaviour within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> int main() { using namespace std; for (int i=0;i<20;++i) ; int t; } When I try to ...

  1. #1
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072

    Strange VC++ 2003 behaviour

    Code:
    #include <iostream>
    
    int main()
    {
        using namespace std;
    
        for (int i=0;i<20;++i)
            ;
    
        int t;
    }
    When I try to compile this code on MSVC++ .NET 2003 i recieve the following error:
    Code:
    c:\...\TestApplication.cpp(13): fatal error C1506: unrecoverable block scoping error
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    Not suprising really. Why are using trying to use " using namespace std;" within a statement block anyway?

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Because it's absolutely valid. It exposes all std content within main without cluttering the global namespace for other functions.

    It more seems to be a compiler bug. Apparently MSVC++ can't handle the vast amount of symbols in std within a function.

    Use selective using declarations and you'll be fine:
    using std::cout;
    using std::endl;
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    If i place a statement between the for-loop and the using-directive, the file compiles fine.

    Every program that I write has "using namespace std;" within its functions so it's not that simple, although it is related.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    Right, I've never used "using namespace" within functions, I didn't even think it was possible! To be honest however, I normally specify namespaces directly for each variable.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Alright. More complicated bug. Does it occur if you enable the for-scope conformance?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Yes, I've tried that and other language options, all with the same result.
    I've also tried the code with two different installations.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  8. #8
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    I'd say report it to MS so it can be fixed in a later patch. It's a program bug for sure.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange behaviour of Ternary
    By Ducky in forum C++ Programming
    Replies: 3
    Last Post: 03-19-2009, 03:17 AM
  2. strange fopen behaviour
    By AngKar in forum C Programming
    Replies: 2
    Last Post: 01-09-2006, 06:58 AM
  3. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 07:51 PM
  4. GetClientRect strange behaviour
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 10-02-2002, 03:13 PM
  5. Strange behaviour
    By PrivatePanic in forum Windows Programming
    Replies: 11
    Last Post: 07-23-2002, 01:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21