CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2006
    Posts
    9

    Not dropping core when referring out of bound address...

    Here's my prog running on solaris10.
    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    struct ThshldActionStat
    {
        char        thshldAction[25];
    };
    
    const int MAX_THSHLDS_PER_GRP_CD = 50;
    typedef ThshldActionStat ThshldGroupActions[MAX_THSHLDS_PER_GRP_CD];
    
    int main()
    {
        ThshldGroupActions *thshldGroupActionStatsOver_;
        ThshldGroupActions *thshldGroupActionStatsUnder_;
    
        thshldGroupActionStatsOver_ = new ThshldGroupActions[55 + 1];
        thshldGroupActionStatsUnder_ = new ThshldGroupActions[55 + 1];
        int i,j;
        for ( i=0;i<59;i++ )
            for(j=0;j<67;j++)
            {
                strcpy( thshldGroupActionStatsOver_[i][j].thshldAction, "" );
                strcpy( thshldGroupActionStatsUnder_[i][j].thshldAction, "" );
            }
        return 0;
    }
    It is running fine... which should drop core in general....
    Can some one please help me here to say what's happening here?

    Thx in advance!
    Last edited by Ejaz; June 23rd, 2008 at 07:27 AM. Reason: Code tags added

  2. #2
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863

    Re: Not dropping core when referring out of bound address...

    the behavior in this case is undefined. It may or may not crash.. If you are lucky then it crashes
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Not dropping core when referring out of bound address...

    Quote Originally Posted by games_icon
    It is running fine... which should drop core in general....
    Welcome to the world of 'C' programming, where writing beyond the boundaries of an array can do *anything*.

    The program may work all the time, it may crash all the time, it may work sometimes and crash other times, it may work all the time on one machine, and crash all the time on another machine, etc...

    As a matter of fact, there is nothing in the 'C' or C++ language definition that guarantees any code to crash -- in C++, you have exceptions, but that is still a language construct.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured