This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: pass bounded array as unbounded
- From: Ian Lance Taylor <iant at google dot com>
- To: Daniel Bengtsson <Danesh dot D at bredband dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: 03 Oct 2007 17:34:10 -0700
- Subject: Re: pass bounded array as unbounded
- References: <13026492.post@talk.nabble.com>
Daniel Bengtsson <Danesh.D@bredband.net> writes:
> I have a already written code in C which should be compiled using GCC. In
> this code there is an 4x3 array which will be passed to a function as
> unbounded array:
>
> int arr[4][3]
>
> myFunc (int myArray[][3])
> {
> int temp=myArray[7][0]
> }
>
> In this function, values out of boundaries of input array is used (like the
> code above). Now I have these questions:
>
> 1. Why I get no error when values out of boundary is used?
> 2. I have checked that for example value of the element [7][0] always has
> same value! I expected at least that this contain random value while it is
> not allocated before. Does GCC fill it with something else or it depends to
> value of other elements in array?
This question is not appropriate for gcc@gcc.gnu.org; the gcc mailing
list is for developers of gcc. You could try the gcc-help@gcc.gnu.org
mailing list. Please send any followups to some other mailing list.
Thanks.
This is not really a gcc question at all. It is a question about how
C works.
1) Inside myFunc there is no information about how long the array is,
so there is no error from referring to an out of bounds element.
2) The value is effectively random. That doesn't mean that you won't
always get the same value. It means that it is unpredictable what
will happen. In practice it depends on the the values of other
global variables in the program.
Ian