VC6 Compiler ignores Array indexing?

Discussion in 'MCSD' started by Ultraman Aries, Jun 4, 2004.

  1. Hi, I'm a newbie VC6 user. I declare an array that holds
    5 elements and when I try to put an error for debugging
    nothing happens. I will be grateful for your effort. ;-)
    ////Heres d code

    int array[5];

    for( int i = 0; i < 6; i++ )
    array = i;

    cout<< array[3] //output: 3 OK!
    << endl
    << array[6]; //output: 6 should be an error!
     
    Ultraman Aries, Jun 4, 2004
    #1
    1. Advertisements

  2. Nope, won't get a compiler error, however you should have had an
    warning displayed in the output window after running in debug mode,
    warning of a stack corruption (or like off).

    So what does this mean? It means C++ is not for children, and by being
    so, generates smaller, quicker code than would be the case if it had
    to perform bounds checking etc.




    Kline Sphere (Chalk) MCNGP #3
     
    The Poster Formerly Known as Kline Sphere, Jun 4, 2004
    #2
    1. Advertisements

  3. Ultraman Aries

    Guest Guest

    If you think that is screwy, try this (switch name and index)

    int array[5]

    for( int i = 0; i < 5; i++ )
    array = i;

    for( int i = 0; i < 5; i++ )
    cout << i[array] << endl;

    ----- Ultraman Aries wrote: ----

    Hi, I'm a newbie VC6 user. I declare an array that holds
    5 elements and when I try to put an error for debugging
    nothing happens. I will be grateful for your effort. ;-
    ////Heres d cod

    int array[5]

    for( int i = 0; i < 6; i++ )
    array = i;

    cout<< array[3] //output: 3 OK
    << end
    << array[6]; //output: 6 should be an error
     
    Guest, Jun 5, 2004
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.