Path: utzoo!attcan!uunet!clyde.concordia.ca!news-server.csri.toronto.edu!turing.toronto.edu!tarvydas From: tarvydas@turing.toronto.edu (Paul Tarvydas) Newsgroups: comp.lang.eiffel Subject: Re: eiffel and external c routines Message-ID: <1990Oct18.105958.2492@jarvis.csri.toronto.edu> Date: 18 Oct 90 14:59:58 GMT References: <444@kepler1.kepler.com> Organization: CSRI, University of Toronto Lines: 93 There's a problem with your C code and with documentation: 1) My copy of 'Eiffel: The Language' incorrectly documents "eif_rout". It returns a *pointer* to a routine. [Also, the names in the C string must be entirely lower case and 25 characters or less.] So, after calling "eif_rout", you still have to call the routine, eg. (*(eif_rout (obj, "feat"))) (obj); or, more humanely put (and, more efficiently, if you're going to make the call more than once): ptr = eif_rout (obj, "feat"); ... (*ptr) (obj); [Remember that you have to supply the "Current" Eiffel object as the first arg to an Eiffel routine.] 2) Your C code is wrong because "item" is a routine, not an attribute (maybe that's why you got the -1 eif_err's). So, here's your C code: ============================ #include #include "/home/Eiffel/files/_eiffel.h" foo(x) OBJPTR x; { int i; extern int eif_err; extern ROUT_PTR eif_rout (); ROUT_PTR item, forth; item = eif_rout (x, "item"); if (item == NULL) { fprintf (stderr, "can't find 'item'\n"); exit (1); } forth = eif_rout (x, "forth"); if (item == NULL) { fprintf (stderr, "can't find 'forth'\n"); exit (1); } for (i = 1; i <= 3; i++) { printf("i = %d (%d) {%d} [%d]\n", i, eif_err, eif_attr (x, "count"), (*item) (x)); (*forth) (x); } } ============================== And here's the output: 1 2 3 i = 1 (0) {3} [1] i = 2 (0) {3} [2] i = 3 (0) {3} [3] As to your question about C-creating instances of generic types, why not write a new class, say "fixed_list_of_integer", then Create it? eg. class FIXED_LIST_OF_INTGER export repeat FIXED_LIST inherit FIXED_LIST [INTEGER] rename Create as flCreate feature Create (n : INTEGER) is do flCreate (n); end; end; Paul Tarvydas tarvydas@tsctrl.uucp TS Controls 5 Bowness Crt. Etobicoke, Ontario, Canada M9B 5Z8 tel. (416)-234-0889, fax. (416)-234-9193