[MLton-devel] runtime convention

Stephen Weeks MLton@mlton.org
Wed, 4 Dec 2002 18:02:30 -0800


> Is there a standard convention for dealing with an ML function that takes
> a string option as a veneer for a runtime C/Posix function that takes a
> possibly NULL char*?  This would seem to be a common C idiom, but I don't
> recall running across an example of this when I was working on basis-2002.

I can't think of any examples either.

> The NetServDB.getBy{Name,Port} functions are like this.  For now, I do a
> case on the string option in ML and dispatch to one of two _ffi functions,
> one that takes a string and the other that has the NULL.  (See
> runtime/basis/Net/NetServDB.c).

I'm happy with two _ffi's.  The only other way I can think of would be
to have one _ffi and to pass the empty string (not null terminated)
for NULL and have the C side detect the empty string by looking at the
array length.  There is no chance for confusion because C strings are
normally null terminated.

If you stay with two functions, I would argue for defining the Null
version by calling the non-Null version.  E.g.

Int NetServDB_getByNameNull (Cstring name) {
	return NetServDB_getByName (name, NULL);
}


-------------------------------------------------------
This SF.net email is sponsored by: Microsoft Visual Studio.NET 
comprehensive development tool, built to increase your 
productivity. Try a free online hosted session at:
http://ads.sourceforge.net/cgi-bin/redirect.pl?micr0003en
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel