Mail Archives: djgpp/1995/12/19/13:13:23
On Tue, 19 Dec 1995, A.Appleyard wrote:
> I compiled this program:-
>
> int zxcvbnm(int i, int j, double x[i][j]){int k; k=2; return 42;}
>
> with djgpp as C and as C++. C++ faulted thus:-
>
> t$$.cc:1: `i' was not declared in this scope
> t$$.cc:1: `j' was not declared in this scope
> Segmentation violation in pointer 0x00000008 at d8:5cebc
>
> EXCEPTION OCCURRED! Information dumped to core file:
> "t$gccdbg"
>
> and C thus:-
>
> C:\WORK>c:\djgpp\bin\gcc t$$.c
> fake(.text+0xe2): undefined reference to `main' /*** I know why that is ***/
>
> (1) Why the difference?
Because C and C++ have different context rules. But this program is
illegal in both. You can't have array dimensions declared as
non-constant values. C isn't Fortran. The segfault is due to problems
with GNU C++ compiler version 2.6.x which sometimes crashes for illegal
programs.
> (2) If I include this function in a C program, would it treat the bounds [i]
> and [j] correctly in the declaration of x, as in Fortran?
No.
- Raw text -