标签: gdc

如何在gdc上施加D2

我从ubuntu的软件中心安装了GDC.

问题是,当我尝试编译包含关键字的源时immutable,它会给我一个错误.然后我推断它只编译D1.

如果我想用GDC编译D2,我该怎么办?

d gdc

6
推荐指数
3
解决办法
553
查看次数

有没有办法创建一个优雅的类成员窗口函数?

Win32 API 中的窗口过程必须是静态\全局函数,因为它不能采用类对象(the this)参数。当然可以使用 hWnd->object 字典等解决方法。

我想知道D是否有办法优雅地解决它,比如为每个对象创建一个微小的成员函数副本(以调用对象的真实处理程序)或我可以分配给的匿名函数WNDCLASS.lpfnWndProc(我知道有匿名函数,但我不能使用extern(Windows)他们的财产)?

我可以做这样的事情吗:


class Window {
    extern (Windows)
    LRESULT delegate (HWND hWnd, UINT msg, WPARAM w, LPARAM l) MyWinProcDelegate;

    this() {
        MyWinProcDelegate = &Events;
    }

    extern (Windows)
    LRESULT Events (HWND hWnd, UINT msg, WPARAM w, LPARAM l) {
        MessageBoxA(null , "Success!!!" , null ,0);
        return DefWindowProcA(hWnd, message, wParam, lParam);
    }
}
Run Code Online (Sandbox Code Playgroud)

(省略注册\创建\msg-loop...)

Events() 似乎没有触发...我错过了什么吗?

winapi d dmd gdc

5
推荐指数
1
解决办法
495
查看次数

哪个D编译器将对此函数执行尾调用优化?

string reverse(string str) pure nothrow
{
    string reverse_impl(string temp, string str) pure nothrow
    {
        if (str.length == 0)
        {
            return temp;
        }
        else
        {
            return reverse_impl(str[0] ~ temp, str[1..$]);
        }
    }

    return reverse_impl("", str);
}
Run Code Online (Sandbox Code Playgroud)

据我所知,这段代码应该进行尾调用优化,但我不知道DMD是否正在这样做.哪个D编译器支持尾调用优化,他们会在这个函数上执行吗?

d dmd gdc

5
推荐指数
1
解决办法
510
查看次数

是否在d中实现了@nogc属性?

我在D中制作了一个计算Fibonacci数字的程序.它应该是最有效的,因为我这样做是为了比较D的执行速度和其他语言的执行速度.然后我在dlang.org上阅读了@nogc属性(这里:http://dlang.org/attribute#nogc ),并试着像这样使用它:

@nogc
@safe
uint fibonacci(uint index)
{
    if(index < 2)
        return index;

    return fibonacci(index - 2) + fibonacci(index - 1);
}
Run Code Online (Sandbox Code Playgroud)

我试过DMD 2.065和GDC 4.8.2,但两个都告诉我: Error: undefined identifier nogc

难道我做错了什么 ?@nogc暂时没有实现吗?

attributes d dmd gdc

4
推荐指数
1
解决办法
459
查看次数

dmd和gdc编译代码有何不同?

我目前正在尝试DerelictSDL2(D的SDL2库绑定),我编写了一个代码,可以成功加载JPG图像并在窗口中显示.也就是说,当它用dmd编译时.当我尝试使用gdc(并且没有代码修改)时,它会编译,但它不会在运行时加载图像.

我相信我做得对:

SDL_Init(SDL_INIT_VIDEO)

然后

IMG_Init(IMG_INIT_JPG)

在那之后的某个地方

this.data = IMG_LoadTexture(Window.renderer, name.ptr)

其中Window.renderer是(明显)的SDL_Renderer*name.ptr是一个char*指向图像的名称来加载.但是,与GDC,编译时IMG_LoadIMG_LoadTexture两回null,而与DMD他们返回一个指针到新创建的质感...

我忘记了别的东西(毕竟,使用dmd它甚至没有工作IMG_Init)?Derelict是否仅适用于dmd(即使它只与C函数接口)?

dmd:2.065

gdc:4.9.1

编辑:

事实证明问题完全不同.IMG_LoadTexture为第二个参数获取指向数据的指针,但name.ptr似乎只适用于dmd.但是,如果我尝试使用这样的硬编码参数:

IMG_LoadTexture(renderer, "../test/res/image.jpg")

它适用于dmd和gdc.

d dmd gdc derelict3 sdl-2

4
推荐指数
1
解决办法
183
查看次数

使用gdc编译D程序时,如何解决“无法识别的选项'-plugin'”?

我下载GDCLinux,并尝试建立一个简单的D程序。执行“ gdc hello.d -o hello”后,输出:

[root@localhost nan]# gdc hello.d -o hello
/usr/bin/ld: unrecognized option '-plugin'
/usr/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

然后,我使用“ gdc -v hello.d -o hello”命令,并尝试查找根本原因。它显示:

......
COLLECT_GCC_OPTIONS='-v' '-o' 'hello' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /home/nan/x86_64-gdcproject-linux-gnu/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/collect2 -plugin /home/nan/x86_64-gdcproject-linux-gnu/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/liblto_plugin.so -plugin-opt=/home/nan/x86_64-gdcproject-linux-gnu/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccWgsSJO.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o hello /usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o /home/nan/x86_64-gdcproject-linux-gnu/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/crtbegin.o -L/home/nan/x86_64-gdcproject-linux-gnu/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0 -L/home/nan/x86_64-gdcproject-linux-gnu/bin/../lib/gcc -L/lib/../lib64 -L/usr/lib/../lib64 -L/home/nan/x86_64-gdcproject-linux-gnu/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../.. /tmp/ccEygjf5.o -lgphobos2 -lm -lpthread …
Run Code Online (Sandbox Code Playgroud)

d gdc

4
推荐指数
1
解决办法
5251
查看次数

我应该确保我的代码与DMD和GDC一起编译吗?

我想部分等价的问题:编译的代码是否应该与DMD一起编译,在GDC的所有情况下自动编译?

我问,因为我在从ubuntu 10.4(看似循环的依赖,叹息)转发中安装现代版本的GDC时遇到了问题.

d dmd gdc

3
推荐指数
1
解决办法
312
查看次数

标准D类型和GDC(LDC)规范

我在哪里可以找到关于GDC(GNU D编译器)的规范以及如何重写像uint等标准D类型?

有关信息:我有兴趣将D用于内核和其他低级别的东西.

谢谢.

d gdc

2
推荐指数
1
解决办法
137
查看次数

方法调用的顺序混淆了

我正在努力学习d所以我从hello world开始,并尝试扩展它.

import std.stdio;
import core.thread;

void main(string[] args){
    writeln("Hello World!");
    Thread.sleep(dur!("seconds")(5));
    writeln("Press enter key to exit...");
    writeln(readln());
}
Run Code Online (Sandbox Code Playgroud)

所以我希望我的输出如下

Hello World!
Press enter key to exit...
//input "abcd"
abcd
Run Code Online (Sandbox Code Playgroud)

但我得到了这个

//input "abcd"
Hello World!
Press enter key to exit....
abcd
Run Code Online (Sandbox Code Playgroud)

睡眠功能甚至被跳过.怎么了?

linux d intellij-idea gdc

1
推荐指数
1
解决办法
129
查看次数

标签 统计

d ×9

gdc ×9

dmd ×5

attributes ×1

derelict3 ×1

intellij-idea ×1

linux ×1

sdl-2 ×1

winapi ×1