unittest can't have extern (C) or import?

Leandro Lucarella llucax at gmail.com
Sun Jan 27 18:54:36 PST 2008


(Moved from digitalmars.D.learn)

Leandro Lucarella, el 27 de enero a las 13:54 me escribiste:
> Second, and whorst, I can't specify extern (C) in the unittest. I need to
> use some functions with C linking, but I can't create them inside the
> unittest. Using extern (C): or extern (C) {} gives me a parse error and
> extern (C) void f() {} parses OK but the extern (C) is ignored and
> compiler complains about trying to use a pointer to a D linked function
> where it expects a C linked function.
> 
> Is this a bug? A feature?
> 
> PS: Using gdc 0.25 (GCC 4.1.3) debian package.

About this second point, it works. It seems to be some problem with nested
extern (C).

The layout of my module is something like:
import x;
extern (C):
// functions and structs
void some_c_func(void function() fp)
{
	// do something with fp
}

unittest
{
	extern (C) static void f() {}
	some_c_func(&f);
}

This doesn't compile with this error:
Error: cannot implicitly convert expression (& f) of type
void(*)() to void(C *)()

The extern (C) is somehow ignored. Is this a bug? (1)

If I replace :
	extern (C) static void f() {}
with:
	extern (C) { static void f() {} }

I get this error:
basic type expected, not {
no identifier for declarator int
semicolon expected, not '{'

Is this another bug? (2)

If I add extern (D): before unittest (and go back to the extern (C)
without the {}) it compiles without errors, so I guess is some error with
the "redundant" extern (C)...

But if I write a simple testcase to expose the bug, I can't make it, it
works. I'm talking about the bug (1), the bug (2) is reproducible in a
simple testcase like this:

void f() {
        extern (C) {
		static void h() {}
	}
}

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
DIEZ "PUNGAS" MENOS
	-- Crónica TV



More information about the Digitalmars-d mailing list