Hi
Is there any technique to avoid array crossing its allocated boundry and corrupting other data.
example:
Code:main() { int A[2]; A[0]=1; A[1]=1; A[2]=1; A[3]=1; }
Hi
Is there any technique to avoid array crossing its allocated boundry and corrupting other data.
example:
Code:main() { int A[2]; A[0]=1; A[1]=1; A[2]=1; A[3]=1; }
Yes. Don't do it. C doesn't do anything nice like always raise an exception when that happens: you have make it right. Best you can hope for is a SIGSIEV.
Ok... is there any way to get SIGSEGV when it crosses the boundry?
Nope.
C does not include "baby sitting" such as bounds or range checking and it is up to you as a programmer to know the sizes of your arrays (etc.) and stay within them.
The answer to the original question is: The only way to prevent array bounds errors is to not write code that gets outside the array boundaries. (as Whiteflags told you).