Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to migrate c to d05

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report