Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!wuarchive!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!ai-lab!opal!mailgzrz!duns1222 From: duns1222@w203zrz.zrz.tu-berlin.de (Martin Dunschen) Newsgroups: comp.lang.eiffel Subject: passing address of an eiffel feature Keywords: fortran, eiffel-c, address passing, complex feature Message-ID: <280@mailgzrz.tu-berlin.de> Date: 5 Mar 91 16:34:44 GMT Sender: news@mailgzrz.tu-berlin.de Organization: TUBerlin Lines: 169 Nntp-Posting-Host: w203zrz.zrz.tu-berlin.de Hello everybody, I have a problem passing the address of an Eiffel feature to a foreign routine, written in C. In the case you want to pass the address of a simple feature, like a real, it seems to be no problem. Also, as given in the example $EIFFEL/examples/.../callbacks, comming along with version 2.3, it is possible to pass pointers to eiffel-routines. But how to pass pointers to complex features, like ARRAY[REAL] ? The reason, we want to do this, is the reuse of software, written in FORTRAN77. If you know this language, you can imagine that there is extensive use of fortran arrays, passed via parameterlists. Because Eiffel 2.3 does not know external clauses with language "Fortran", we use short C procedures, which call the Fortran subroutines. The argument passing and all other problems using C together with Fortran are already solved. To supply the Fortran subroutine with these arrays, or getting back the results of a computation on an array, we think about using the possibility of passing pointers of Eiffel features to foreign routines, this is descibed very brief in "Eiffel: The language (version 2.2)", pages 218, 219. Perhaps there is a workaround? Nevertheless I include a few C routines and eiffel-classes, showing in two examples what I mean. You cut this file at the indicating lines, put the parts in new files, named .eiffel, test.e, c_test.c for example 1 in one directory, and the others, with same names in another directory. Compile the C-routine in each directory and invoke es. The executable in example 1 does what I expect, example 2 is somehow a clue for me! Thanks in advance, Martin +-----------------------------------------------------------------+ | e-mail: dunschen@zrzsp9.fb12.tu-berlin.de | | dunschen@DB0TUS11.BITNET | | | | voice : +49.+30.31424109 | | fax : +49.+30.31426883 | +-----------------------------------------------------------------+ CUT HERE ------CUT HERE ------CUT HERE ------CUT HERE ------CUT HERE ------ -- -- Beginning of first example, following files are .eiffel, test.e, c_test.c -- ------------ EIFFEL SYSTEM DESCRIPTION FILE ------------------- -- For simple uses, just replace ``root_class_name'' below -- by the name of the root class of your system (lower case) ROOT: test UNIVERSE: $EIFFEL/library/structures $EIFFEL/library/support EXTERNAL: c_test.o NO_ASSERTION_CHECK (N): ALL PRECONDITIONS (Y): ALL ALL_ASSERTIONS (N): ALL DEBUG (N): TRACE (N): OPTIMIZE (N): ALL GARBAGE_COLLECTION (N) C_PACKAGE (N): C_EXTERNAL: MAKE: VISIBLE (N): CUT HERE ------CUT HERE ------CUT HERE ------CUT HERE ------CUT HERE ------ --| --| test.e --| class TEST feature value : REAL; Create is external c_test language "C" do value := 25.; io.putstring (" this is test.e value="); io.putreal (value); io.putstring ("\n"); c_test (@value); io.putstring (" this is test.e, after c_test value="); io.putreal (value); io.putstring ("\n"); end --create end -- class TEST CUT HERE ------CUT HERE ------CUT HERE ------CUT HERE ------CUT HERE ------ /* c_test.c */ c_test (parm) float *parm; { printf ("this is c_test, parm= %f \n", *parm); *parm = *parm +25.; } CUT HERE ------CUT HERE ------CUT HERE ------CUT HERE ------CUT HERE ------ -- -- Beginning of second example, following files are .eiffel, test.e, c_test.c -- ------------ EIFFEL SYSTEM DESCRIPTION FILE ------------------- -- For simple uses, just replace ``root_class_name'' below -- by the name of the root class of your system (lower case) ROOT: test UNIVERSE: $EIFFEL/library/structures $EIFFEL/library/support EXTERNAL: c_test.o NO_ASSERTION_CHECK (N): ALL PRECONDITIONS (Y): ALL ALL_ASSERTIONS (N): ALL DEBUG (N): TRACE (N): OPTIMIZE (N): ALL GARBAGE_COLLECTION (N) C_PACKAGE (N): C_EXTERNAL: MAKE: VISIBLE (N): CUT HERE ------CUT HERE ------CUT HERE ------CUT HERE ------CUT HERE ------ class TEST feature list : ARRAY[REAL]; Create is external c_test language "C" do list.create(0,2); list.put ( 10.,0); list.put ( 20.,1); list.put ( 30.,2); io.putstring ("test, before c_test:\n"); io.putreal (list.item (0)); io.putstring ("\n"); io.putreal (list.item (1)); io.putstring ("\n"); io.putreal (list.item (2)); io.putstring ("\n"); c_test (@list); io.putstring ("test, after c_test:\n"); io.putreal (list.item (0)); io.putstring ("\n"); io.putreal (list.item (1)); io.putstring ("\n"); io.putreal (list.item (2)); io.putstring ("\n"); end --create end -- class TEST CUT HERE ------CUT HERE ------CUT HERE ------CUT HERE ------CUT HERE ------ c_test (list) float *list; { printf ("this is c_test, list(0)= %f \n", list[0]); printf (" list(1)= %f \n", list[1]); printf (" list(2)= %f \n", list[2]); list[0] = list [1] + list [2]; }