Problem with C interface

Gustavo A. Ospina g-ospina at uniandes.edu.co
Sun Oct 4 01:51:18 AEST 1998


Good day to all.

I want to make an encryption function in Mercury using the unix C
function crypt (to proof Mercury to C interface). This is the
module:

%--------------------------------------------------------------
:- module crypt2.

:- interface.

:- func crypt2(string,string) = string.
:- mode crypt2(in,in) = out is det.

:- implementation.

:- pragma c_header_code("#include <unistd.h>").

:- pragma c_code(crypt2(Key::in, Salt::in) = KeyCrypted::out, 
                 will_not_call_mercury,
                 "KeyCrypted = crypt(Key,Salt);").
%--------------------------------------------------------------

Compiling this program, I got this error message:

crypt2.m:012: Error: arguments not in form 'Var :: mode': crypt2(_0 :: in,
_1 :: in) = _2 :: out.

After I saw that is not working, I try to use a predicate instead of a
function.

%--------------------------------------------------------------
:- module crypt.

:- interface.

:- pred crypt(string,string,string).
:- mode crypt(in,in,out) is det.

:- implementation.

:- pragma c_header_code("#include <unistd.h>").

:- pragma c_code(crypt(Key::in, Salt::in, KeyCrypted::out), 
                 will_not_call_mercury,
                 "KeyCrypted = crypt(Key,Salt);").
%--------------------------------------------------------------

This program compile and work well, although the difference is very subtle
between the two approaches (functional: more natural; predicate: purely
logical). Hence, seems there are a problem in the C interface when it
implements a function.

Are there an error in the syntax or C interface for functions is not
suported in the current release? will be suported in your next release?

Thanks to all and have a nice day.

+ Gustavo.

	+---------------------------------------+
	|  Gustavo A. Ospina                    |
	|  MEngSc Student                       |
	|  Computing and Systems Engineering    |
	|  University of Los Andes              |
	|  Santafe de Bogota D.C., Colombia     |
	|  e-mail: g-ospina at uniandes.edu.co     |
	+---------------------------------------+




More information about the users mailing list