Variable declaration after function's argument list

c, declaration, function, syntax

Solution

This is an old notation known as K & R (Kernighan & Ritchie, after Brian Kernighan and Dennis Ritchie) Notation for declaring the functions. If your compiler supports it, you can use it and it is same as declaring the function with ANSI notation.

Problem

I stumpled upon a C code, where variables seem to be declared after the argument list of a function. I did not know that this was possible. In the code, `int r` and `int *a` are declared right after the argument list of `arr2int`. How does this affect the local variables `a` and `r` of `arr2int`? The actual reason why I want to understand the code is because if I let it run on my linux x86 `a[1] = 1` at `//MARKER` when `arr2int` ist called the fist time. But if I let it run ona an ARM-based omap4 dev board `a[1]=0` and I dont know why there is a difference. Could someone comment on this please? ``` long arr2int(a,r) int r; int *a; { int i; long mul, result = 0, temp; //MARKER for (i=1; i<=r; i++) { mul = 1; temp = a[i]-1; while (temp--) mul = mul << 1; result += mul; } return(result); } ``` And the calling method: ``` void generateEncodingTable(){ register int i,j; long temp; int seed = 133757; printf("\n[I] - Generating Encoding Table\n"); for (pattern = 0; pattern < 4096; pattern++) { temp = pattern << 11; /* multiply information by X^{11} */ encoding_table[pattern] = temp + get_syndrome(temp);/* add redundancy */ } decoding_table[0] = 0; decoding_table[1] = 1; temp = 1; for (i=2; i<= 23; i++) { temp *= 2; decoding_table[get_syndrome(temp)] = temp; } a[1] = 1; a[2] = 2; temp = arr2int(a,2); decoding_table[get_syndrome(temp)] = temp; for (i=1; i<253; i++) { nextcomb(23,2,a); temp = arr2int(a,2); decoding_table[get_syndrome(temp)] = temp; } a[1] = 1; a[2] = 2; a[3] = 3; temp = arr2int(a,3); decoding_table[get_syndrome(temp)] = temp; for (i=1; i<1771; i++) { nextcomb(23,3,a); temp = arr2int(a,3); decoding_table[get_syndrome(temp)] = temp; } } ```

Original source

Related problems