| Thread overview | |||||
|---|---|---|---|---|---|
|
January 27, 2008 unittest can't have extern (C) or import? | ||||
|---|---|---|---|---|
| ||||
Hi! I'm trying to do some unittest on a C bindings. First, I found I can't use import inside a unittest block (why?). Should I polute the module with symbols I only want for the unittest? :S
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?
TIA.
PS: Using gdc 0.25 (GCC 4.1.3) debian package.
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
"The Guinness Book of Records" holds the record for being the most stolen book in public libraries
| ||||
January 27, 2008 Re: unittest can't have extern (C) or import? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Leandro Lucarella | "Leandro Lucarella" <llucax@gmail.com> wrote in message news:20080127154946.GA27400@homero.springfield.home... > Hi! I'm trying to do some unittest on a C bindings. First, I found I can't use import inside a unittest block (why?). Should I polute the module with symbols I only want for the unittest? :S > > 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? > > TIA. > > PS: Using gdc 0.25 (GCC 4.1.3) debian package. A unittest block is a function body. Anything that's illegal in a function body is also illegal in a unittest block. I would kind of like imports to be legal in functions but that's another story. Basically there's no built-in solution to this. Tango does something like: debug(UnitTest) { import my.stuff; extern(C) void some_func(); unittest { some_func(); my.stuff.fweep(); } } And when running unittests they'll also define a UnitTest debug symbol. Not built-in but it works. | |||
January 28, 2008 Re: unittest can't have extern (C) or import? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Leandro Lucarella | (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 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply