Get the App
SLTechnology News&Howtos  ›  Development  › 

How to migrate c to d05

Shulou Source: shulou.com Published: 2022-06-03 05:54:43 10月15日 Update

This article mainly explains "how to transplant c to d05". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to transplant c to d05.

/ / In C

Typedef struct foo_s

{

Int x

Struct foo_s * next

} foo_t

/ / A _

/ / In D

Struct foo_t// uses the back one.

{

Int x

Foo_t * next

}

And the opaque structure of c / forward reference of C++

/ / In C

Typedef struct foo_s foo_t

/ / In D

Struct foo_t

Translation structure members, also similar, Typedefs, Aliases, and local types, but there are some pitfalls. When naming functions / types, try to be the same as c. But sometimes the name in c has the keyword d. Therefore, it is common to add a _. Then explain it in the document.

/ / In C

Typedef struct

{

/ / d keyword.

Int module

} foo_t

/ / In D

Struct foo_t

{

Int _ module;// plus _.

}

There are also some c library members, wrapped in # define blocks. When binding and using c library, it is easy to make mistakes and convert d easily, but be careful when using it.

/ / In C

Typedef struct

{

Float x

Float y

# ifdef MYLIB_GO_3D

Float z

# endif

} foo_t

/ / In D

Struct foo_t

{

Float x

Float y

/ / use version qualifying block, name related to the environment

Version (Go3D) float z

}

Add the-version=Go3D switch when compiling. If the binding is a library, the application should also be added. This is a hassle. C libraries should be compiled in the same way. If it is public, add the version document. It's really a trick.

There is also a pit, that is, the bit field, which is generally solved by the std.bitmanip library, but not a specific drug, because the c standard does not define the order of the bit field.

Typedef struct

{

Int x: 2

Int y: 4

Int z: 8

} foo_t

There is no guarantee of the order of the fields and whether and where to fill in the blanks. Different compilers and different platforms are different. It has to be matched manually. You can consider using std.bitmanip.bitfields

/ / std.bitmanip.bitfields for D

Struct foo_t

{

Mixin (bitfields!) (/ / to convert

Int, "x", 2

Int, "y", 4

Int, "z", 8

Int, "", 2)); / / padding

}

Must be a multiple of 8, there are 2 vacant seats above. Start with the least important position. Must match the c compiler.

The rest is used

Struct foo_t

{

Int flags

Int x () @ property {...}

Int y () @ property {...}

Int z () @ property {...}

}

At this point, I believe you have a deeper understanding of "how to transplant c to d05". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Compile migrate different key keyword content name that is member document version type structure compiler order learning practical deeper important almost Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MariaDB Shulou Technology macOS MySQL