我最近在我的Mac上通过hombrew安装了ldc,当我注意到使用ldmd2来编译我的程序时,我正在测试运行代码作为D wiki中的脚本.差异是什么,因为这与运行ldc2的行为相同.
继承我的计划
import std.stdio;
void main()
{
writeln("Hello, world without explicit compilations!");
}
Run Code Online (Sandbox Code Playgroud)
编辑:该网站声明"对于小型项目,它只需一步编译和运行.大多数(如果不是全部)编译器包,包含一个名为rdmd/gdmd/ldmd或类似的工具.出于教学目的,我们称之为rdmd ".我从中获取的是它取决于您使用的编译器,但在ldc的情况下我应该使用ldmd.
我正在尝试与C++和D进行互操作.而我今天发现的东西真的让我大吃一惊:对象没有在我的程序中正确传递.
最好是展示一个例子.
我有一个C++库,我编译成一个目标文件和D程序,我与我的库链接并运行.
他们来了:
#include <stdio.h>
class Color
{
public:
Color(unsigned int _r, unsigned int _g, unsigned int _b) : r(_r), g(_g), b(_b) {}
unsigned int r, g, b;
};
class Printer
{
public:
Printer() {}
~Printer() {}
static Printer* getInstance();
void print(Color *c);
};
Printer* Printer::getInstance()
{
return new Printer();
}
void Printer::print(Color *c)
{
printf("(%d, %d, %d)\n", c->r, c->g, c->b);
}
Run Code Online (Sandbox Code Playgroud)
和D程序:
import std.stdio;
extern(C++)
{
class Color
{
uint r, g, b;
this(uint _r, uint _g, uint …Run Code Online (Sandbox Code Playgroud) 提前道歉,因为我对这个主题还不太了解,并且仍在学习编译器的内部工作原理。
我目前正在研究在嵌入式系统中使用 D 的可能性,并发现一篇文章提到 AVR 后端如何合并到上游 LLVM 项目中,以便开发人员可以致力于为他们的语言创建 AVR 支持。D 有 LDC 编译器,它使用 LLVM 后端。不过,这篇文章还提到了 avr-gcc 的使用,这让我对在哪个阶段使用哪些工具从 D 源代码到 AVR 二进制文件有点困惑。我假设 LDC 将源代码转换为 LLVM IR,然后转换为二进制,所以我不确定 avr-gcc 的用途。
有人可以更详细地向我解释这一点吗?
我使用Dim的Deimos openssl标头将D链接到OpenSsl,并使用ldc 1.8.0编译器,尝试将字符串加密为小测试.加密的字节数组与我的预期不一致.当我运行程序并加密字符串并在之后对其进行解密后,我将原始字符串恢复.但是中间加密字节数组在代码执行之间不一致.
所以我的问题是,这是预期的行为,并且OpenSsl中的AES是否会为内容添加某种盐,因此攻击更难,或者这是我的错误?
import std.stdio;
import std.conv;
import std.string;
import std.outbuffer;
import deimos.openssl.aes;
void main()
{
writeln("hello world");
const auto encryption_passphrase = "foo!";
writeln("The encryption key is \"" ~ encryption_passphrase ~ "\"");
const auto encryption_content = "bar";
writeln("The to be encrypted content is: \"" ~ encryption_content ~ "\"");
writeln("The content lenght is " ~ encryption_content.length.to!string);
writeln("----------");
writeln("encrypting");
AES_KEY encryption_key;
AES_set_encrypt_key(cast(ubyte*) encryption_passphrase.toStringz, 128, &encryption_key);
OutBuffer buf = new OutBuffer();
buf.write(encryption_content);
ubyte[] inbuffer = buf.toBytes();
ubyte[] encryptedbuffer = new ubyte[inbuffer.length];
AES_encrypt(&inbuffer[0], …Run Code Online (Sandbox Code Playgroud) 我有兴趣学习D.然而我有点被DMD所转变,因为它不是完全开源的.这就是我考虑使用LDC的原因,但我不确定它的状态是什么.在debian包中它说:
Version: 1:0.14.0.dfsg-1
LDC already compiles a lot of D code, but should still be considered beta quality. Take a look at the
tickets to get a better impression on what still needs to be implemented.
Run Code Online (Sandbox Code Playgroud)
我知道Debian存储库有时可能有点古老,但1.0.0似乎是最新的LDC版本.
我打算使用C语言编写的库.哪个编译器更适合这个目的?LDC还是DMD?我知道之前已经问过这个问题,但我发现的所有问题都比较陈旧,我想知道当前的状态.