From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,64e0d99757a2e3e6 X-Google-Attributes: gid103376,public From: Mats Weber Subject: Re: HELP: Problem with C function called in Ada Date: 1997/02/07 Message-ID: <32FB6616.5A2F@elca-matrix.ch>#1/1 X-Deja-AN: 215311664 references: content-type: text/plain; charset=us-ascii organization: ELCA Matrix SA mime-version: 1.0 reply-to: Mats.Weber@elca-matrix.ch newsgroups: comp.lang.ada x-mailer: Mozilla 3.01 (Macintosh; I; PPC) Date: 1997-02-07T00:00:00+00:00 List-Id: > procedure keys is > > X: character; > > procedure Get_immediate(X:character); Problem: should be X : out Character if you want something back from the call. > pragma interface(C, Get_immediate); > pragma interface_name(Get_immediate,"getc"); Another problem: in C (I am not sure, but I think) getc is a function and you should interface it as a function: function Get_immediate return Character; > package int_io is new text_io.integer_io(integer); > use int_io; > > begin > loop > Get_immediate(X); > Put_line(Natural'Image(character'pos(X))); > skip_line; > end loop; > end keys; > > The following problems encountered are: > > when I compile this code (ada keys.a, and ada -M keys -o keys.o), i > obtain the following warning: > Warning: variable may not have a value. This is normal. With your original declaration of Get_Immediate, a call is a read of the variable X (instead of a write if the paramter has mode out). Reading uninitialized scalar variables is forbidden. > If I run the code, I got a "Bus Error (code dumped)" !!! that's probably a result of not interfacing getc correctly. If it's a function, make it a function in Ada too. > The warning disappear if I set a "X:=' '" just after the begin. But not the core dump, right ? This is normal (see above). > The Put_line(Natural'...) is to obtain the code of the key pressed > (especially arrow keys). Is it correct? Beware of arrow keys: they often return more than on character (escape sequences).