www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Library Suggestion

reply Jeremy <Jeremy_member pathlink.com> writes:
OK, I have another idea for easier library integration. :)

You have this at the top of your code:

#pragma(lib,"whatever.lib")

instead of having to do an "extern(C) void whatever_func010(int, int)" for every
function, just grab this information from unresolved symbols. Like:

--------------------------
#pragma(lib,"whatever.lib");

int main() {
int a, b;
whatever_func010(a,b);
return 0;
}
--------------------------

When it compiles, the 'whatever_func010' will be unresolved -- but you have the
symbol name and argument types -- you could use this information to create the
same information as in the "extern" definition line. Then, you wouldn't need to
explicitly define each function name -- just referencing the function (with the
correct argument types) will tell the linker the symbol name/args etc.

If you need to know the type (e.g. "C" as in "extern(C)") you could add that to
the #pragma line:

#pragma(lib,"whatever.lib",C);

Jeremy
Mar 27 2006
parent "Lionello Lunesu" <lio remove.lunesu.com> writes:
"Jeremy" <Jeremy_member pathlink.com> wrote in message 
news:e0968a$1nbm$1 digitaldaemon.com...
 OK, I have another idea for easier library integration. :)

 You have this at the top of your code:

 #pragma(lib,"whatever.lib")

It's pragma without the #.
 instead of having to do an "extern(C) void whatever_func010(int, int)" for 
 every
 function, just grab this information from unresolved symbols. Like:

 --------------------------
 #pragma(lib,"whatever.lib");

 int main() {
 int a, b;
 whatever_func010(a,b);
 return 0;
 }
 --------------------------

I can see how this would help, but what if you use constants in the function call? Like, whatever_func(1,2); How does the compiler know the types of the prototype? They can be int, uint, long, ulong, byte, ubyte. In fact, they can get promoted to float,double,real as well. The only way around this is to assume "int" in these cases, but that sounds like C's behaviour (assuming int when no type is present) and frankly I think it's pretty vague reasoning. Lio.
Mar 28 2006