Some doubts on variable-length array



Hello experts,

I have seen following the code snippet given by Marc Boyer (with slight
changes by me for a better format), and have doubts on it. I am so
grateful if you can give me your kindly help and hints on this problem.

1. Does the function call `foo(3, 3, tab);' refer to the data outside
the array `int tab[9];'. The available subscription for a 3X3 2-D array
should be 0..2 X 0..2, I think.

2. For the available function call `foo(2, 2, tab);' (I do not think
the second one is unavailable, just not sure.), which element in the
array `int tab[9];' does tab[0][0] refer to inside the body of the
function `foo'. I want to know the exact one int the format `tab[0] ..
tab [8]'.

And which element in `int tab[9];' does tab[1][1] refer to.

I can not figure it out for some while on it. The GCC4.1 says it does
not support the variable-length array of C99, but I can compile this
program on even GCC3.3.5, and also on GCC4.1 after I installed this
newest one. I also get the same result of the program as Marc Boyer.

Sincerely,

lovecreatesbeauty



/* sample by Marc Boyer */

#include <stdio.h>

void
foo(int size_x, int size_y, int tab[size_x][size_y])
{
printf("tab[1][1] == %d\n", tab[1][1]);
}

int
main()
{
int tab[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
foo(2, 2, tab);
foo(3, 3, tab);

return 0;
}

news> ./a.out
tab[1][1] == 3
tab[1][1] == 4

.



Relevant Pages

  • Re: Equation line numbers
    ... I use different margin settings for different kinds ... So setting the right tab for the equation number to 6 will not ... I checked the MathType Help file, and I didn't find any reference to ... To format the equation numbers, ...
    (microsoft.public.word.pagelayout)
  • Re: Corrupt Word Doc While Editing
    ... Word does not "auto format" your document unless you tell it to using ... On the AutoFormat As You Type tab, ... Disable this at on the Save tab of Tools | Options. ... Embedded graphics: When feasible, it is preferable to link the ...
    (microsoft.public.word.formatting.longdocs)
  • Re: Macro for inserting numbered equations-error
    ... included inserting the blank equation. ... NeoOffice and the ODF format. ... I would be tempted not to bother with a macro at all. ... I set a centering tab at the ...
    (microsoft.public.mac.office.word)
  • Re: Random Number Generation & VLOOKUP
    ... I've changed the format slightly. ... each tab represents a module number. ... range in the random number generator? ... I keep getting the message "Numbers in discrete probability ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Many small programs vs. one large program?
    ... code format, etc... ... format, not the input or output data files... ... many compilers, I believe Intel's are among them, ... Many DEC-heritage compilers, including CVF and IVF, allowed "tab ...
    (comp.lang.fortran)