[Home]
[Search]
[D]
dmc -c program.h -e -lwill create a file program.lst which is the source file after all text preprocessing.
Remove all the #if, #ifdef, #include, etc. statements.
extern (C)
{
...file contents...
}
to give it C linkage.
| C type | D type |
|---|---|
| long double | real |
| unsigned long long | ulong |
| long long | long |
| unsigned long | uint |
| long | int |
| unsigned | uint |
| unsigned short | ushort |
| signed char | byte |
| unsigned char | ubyte |
| wchar_t | wchar or dchar |
| bool | int |
L"string"with:
cast(wchar[])"string"
#define FOO 1 #define BAR 2 #define ABC 3 #define DEF 40can be replaced with:
enum
{ FOO = 1,
BAR = 2,
ABC = 3,
DEF = 40
}
or with:
const int FOO = 1; const int BAR = 2; const int ABC = 3; const int DEF = 40;Function style macros, such as:
#define MAX(a,b) ((a) < (b) ? (b) : (a))can be replaced with functions:
int MAX(int a, int b) { return (a < b) ? b : a); }
int *p, q, t[3], *s;should be written as:
int* p, s; int q; int[3] t;
int foo(void);are in D:
int foo();
void foo(const int *p, char *const q);becomes:
void foo(int* p, char* q);
typedef int foo;becomes:
alias int foo;
typedef struct Foo
{ int a;
int b;
} Foo, *pFoo, *lpFoo;
with:
struct Foo
{ int a;
int b;
}
alias Foo* pFoo, lpFoo;
#pragma pack(1)
struct Foo
{
int a;
int b;
};
#pragma pack()
becomes:
struct Foo
{
align (1):
int a;
int b;
}
struct Foo
{
int a;
struct Bar
{
int c;
} bar;
};
struct Abc
{
int a;
struct
{
int c;
} bar;
};
becomes:
struct Foo
{
int a;
struct Bar
{
int c;
}
Bar bar;
};
struct Abc
{
int a;
struct
{
int c;
}
};
int __cdecl x; int __cdecl foo(int a); int __pascal bar(int b); int __stdcall abc(int c);become:
extern (C) int x; extern (C) int foo(int a); extern (Pascal) int bar(int b); extern (Windows) int abc(int c);
__declspec(dllimport) int __stdcall foo(int a);becomes:
export extern (Windows) int foo(int a);
int __fastcall foo(int a);
int myfoo(int a)
{
return foo(int a);
}
and compiled with a C compiler that supports __fastcall and
linked in, or compile the above, disassemble it with
obj2asm
and insert it in a D myfoo shim with inline assembler.