Mail Archives: cygwin/2000/11/20/10:43:39
Hi,
I am using the gcc compiler under Cygwin on a NT platform for applications
where I call Fortran subroutines from C code. This is working smoothly with
one strange exception: If more than one string are present in Fortran
subroutines the program crashes. Apparently everything works with ONE string
only. The following simple example illustrates the problem:
-------- main.c ----------
#include <stdio.h>
extern void sub1_(char *s1, unsigned int);
extern void sub2_(char *s1, unsigned int, char *s2, unsigned int);
int main() {
static char s1[] = "String1 ver 0";
static char s2[] = "String2 ver 0";
/* This works well */
printf("\n First test:\n");
printf(" In main: s1 = %s. Length = %d\n", s1, strlen(s1));
sub1_(s1, strlen(s1));
printf(" In main: s1 = %s. Length = %d\n", s1, strlen(s1));
/* This crashes */
printf("\n Second test:\n");
sub2_(s1, strlen(s1), s2, strlen(s2));
printf(" In main: s1 = %s. Length = %d\n", s1, strlen(s1));
printf(" In main: s2 = %s. Length = %d\n", s2, strlen(s2));
return(0); }
-------- sub1.f -------
SUBROUTINE SUB1(S1)
*
CHARACTER*(*) S1
*
WRITE(*, *) 'In SUB1: S1 = ', S1, '. Length = ', LEN(S1)
*
S1 = 'String1 ver 1'
RETURN
END
------- sub2.f -------
SUBROUTINE SUB2(S1, S2)
*
CHARACTER*(*) S1, S2
*
WRITE(*, *) 'In SUB2: S1 = ', S1, '. Length = ', LEN(S1)
WRITE(*, *) 'In SUB2: S2 = ', S2, '. Length = ', LEN(S2)
*
S1 = 'String 1 ver 2'
S2 = 'String 2 ver 2'
*
RETURN
END
------- makefile -------
test: main.o sub1.o sub2.o
gcc -Wall -o test main.o sub1.o sub2.o -lg2c
main.o: main.c
gcc -Wall -c main.c
sub1.o: sub1.f
gcc -Wall -c sub1.f
sub2.o: sub2.f
gcc -Wall -c sub2.f
------- output -------
First test:
In main: s1 = String1 ver 0. Length = 13
In SUB1: S1 = String1 ver 0. Length = 13
In main: s1 = String1 ver 1. Length = 13
Second test:
In SUB2: S1 =
0 [main] test 1000 handle_exceptions: Exception:
STATUS_ACCESS_VIOLATION
1036 [main] test 1000 stackdump: Dumping stack trace to
test.exe.stackdump
-----------------
Can any one tell me what's wrong and how I possible can avoid the problem?
Kind regards
Erik Nim
Risoe National Laboratory
Wind Energy and Atmospheric Physics Department
Denmark
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com
- Raw text -