This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pass bounded array as unbounded

Daniel Bengtsson <> 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; the gcc mailing
list is for developers of gcc.  You could try the
mailing list.  Please send any followups to some other mailing list.

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]