extended foreign decls

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Tue Jan 2 13:35:18 EST 2001

Tue, 2 Jan 2001 22:28:02 +1100, Fergus Henderson <fjh at cs.mu.oz.au> pisze:

> Doing it in a separate tool will lose efficiency in some important
> cases.  If the compiler is compiling via C, then it can insert
> inline C code directly in the generated code, and thus get
> inlining.  But I think a separate tool would have to put the C code in
> a separate C file, which would prevent inlining.

hsc2hs creates a .c file and a .h file for snippets of C code.
The .h file is included into the .hc file generated by ghc.
If you mark functions as inline, they will be really inlined.

BTW. gcc understoods the word "inline" differently than ISO/ANSI C99
defines it. The following files are produced from a simple source:
    #include <errno.h>
    #def inline HsInt get_errno (void) {return errno;}
It works with gcc and should work with a hypothetical C compiler which
understands inline correctly.

-------- .h file --------

#ifndef TEST_HS_H
#define TEST_HS_H
#include <Rts.h>
#include <HsFFI.h>
#include <errno.h>
#ifdef __GNUC__
inline HsInt get_errno (void) {return errno;}

-------- .c file --------

#include "Test.hs.h"
#ifndef __GNUC__
inline HsInt get_errno (void) 
#ifndef __GNUC__
{return errno;}

 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
  ^^                      SYGNATURA ZASTÊPCZA

More information about the FFI mailing list