Thread: why i get this run time error..

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    why i get this run time error..

    i do some operations on an array
    its all ok..

    i dont get "accsses of cell beyong the array" anywhere when i fill the array.

    but when i live the function i get
    "Run-Time Check Failure #2 -Stack around the variable 'gh' was corrupted
    ??

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    C is like a loving parent. It likes you to learn from your mistakes. It's not going to stop you from wandering off the path into the tiger infested jungle. It knows that you'll eventually learn from your mistakes.

    Even if that means you get mauled by a tiger.

    C loves you.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    but i should get an error on some operation on the array
    why it goes on the last line of the function

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why should it? Undefined behavior is just that, undefined. Anything can happen. That's why we get posts like "This code worked for me!" when they're copying stuff into pointers which haven't been assigned any value, etc. It MIGHT let you access that memory, it might not:
    Code:
    int *x;
    *x = 10;
    Maybe it crashes, maybe it doesn't. Maybe it does for you, but not for me? Who knows. It's not defined.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by transgalactic2 View Post
    but i should get an error on some operation on the array
    why it goes on the last line of the function
    Because to keep some resemblance of performance, the compiler only checks that you haven't wandered off into the weeds when the function returns, rather than every single memory access.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    on codeblocks compiler it works fine
    but on VS it gives me that run time error
    ??

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by transgalactic2 View Post
    on codeblocks compiler it works fine
    but on VS it gives me that run time error
    ??
    No, in Code::Blocks, the error goes undetected - that is not the same as "works fine". That is, as quzah describes, one of the probems with undefined behaviour. Writing outside an array [which I'm fairly sure is what you are doing - posting your code would help a lot] is undefined behaviour, it may cause ANYTHING to happen, and "anything" includes "nothing that you actually notice" as well as crashes, nuclear launch and explosion of the hard-disk.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    thanks i solved it
    you are correct

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM