how closely does vc++.net 2003 follow ANSI?

This is a discussion on how closely does vc++.net 2003 follow ANSI? within the C++ Programming forums, part of the General Programming Boards category; At home, I work with visual c++ 6.0 standard. As a programming beginner, I have already noticed that it does ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    40

    how closely does vc++.net 2003 follow ANSI?

    At home, I work with visual c++ 6.0 standard.

    As a programming beginner, I have already noticed that it does not follow the ANSI standards in several ways.

    For example, in the book I'm reading, it says that when you declare a variable in a for loop, it is restricted to that code block, by ANSI standards. However, vc++ 6 doesn't obey this rule, I have noticed.

    My friend's dad has visual c++ .net 2003, and I noticed the same thing happens.

    This seems weird. On the microsoft website, it said that vc++ 2003 is much more conformative to ANSI...

    Is this just one weird example?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    For example, in the book I'm reading, it says that when you declare a variable in a for loop, it is restricted to that code block, by ANSI standards. However, vc++ 6 doesn't obey this rule, I have noticed.
    Are you sure about that? The following gives me an error with MSVC++ 6.0

    Code:
    int main(void)
    {
        for(;;)
    	{
    		int i = 10;
    	}
    	i = 12;
    }

  3. #3
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Code:
    #include <iostream>
    
    int main ()
    {
    
        for ( int loop = 0; loop < 2; loop++ ) {
    
            std::cout << loop;
    
        }
    
        // This compiles and prints '2'
        std::cout << loop;
    
        return 0;
    
    }
    MSVC++ 6.0 Pro
    What is C++?

  4. #4
    Registered User
    Join Date
    Jun 2004
    Posts
    40
    hmm..

    the exact words of the book are as follows:

    "whether a variable is declared within the initialization portion of a for loop is restricted to that loop has changed over time... today, the ansi/iso standard restricts the variable to the scope of the for loop."

    i took that to mean that the variable declared in that specific place:

    Code:
    int main(void)
    {
        for(int n=5;;)
    	{
    		
    	}
    	n=7;
    }
    that seems to work... but the book acts like it shouldn't

    edit: yeah, that's what vicious was getting at
    Last edited by krygen; 09-22-2004 at 01:06 AM.

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    MM hmm, I dont think it is supposed to...
    What is C++?

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    You have to turn that feature on in VC2003, it's off by default for backwards compatibility. In the project properties, chose "C++"->"Language" and select "Force Conformance In For Loop Scope".

    The compiler switch would be "/Zc:forScope"

    Code:
    	for( int i = 0 ; i < 10 ; i++ )
    	{
    		printf( "%d\n", i );
    	}
    
    	i = -1;
    error C2065: 'i' : undeclared identifier
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  7. #7
    Registered User
    Join Date
    Jun 2004
    Posts
    40
    brilliant. thank you nvoigt

  8. #8
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    You can do the same in Visual C++ 6.0 by using the /Za compiler switch.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. VC++ 6.0 vs .NET 2003
    By Frantic- in forum C++ Programming
    Replies: 4
    Last Post: 06-26-2005, 09:41 AM
  2. Visual C++Toolkit 2003 and .NET 1.1
    By Joelito in forum Windows Programming
    Replies: 1
    Last Post: 05-13-2005, 10:27 PM
  3. Visual C++ .NET 2003 and XP Style
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 10-07-2003, 12:08 PM
  4. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 07:51 PM
  5. Visual J#
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 03:41 PM

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