小编Joh*_*n_C的帖子

在D中使用带数组的构造函数

在使用new分配数组时如何调用构造函数?

例如,在下面的代码中,如何为A的每个实例化调用构造函数,将b的所有10个元素初始化为5?

void main() {
    A[] a = new A[10];
}

class A {
    int b;
    this(int init) {
        b = init;
    }
}
Run Code Online (Sandbox Code Playgroud)

我猜这不可能,但我希望......

arrays constructor d dynamic-arrays

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

从交互式shell调用d代码

我需要一个交互式环境,我可以使用一个很好的脚本语言和一些体面的科学绘图库(例如python)来动态调用d函数.

有没有办法从shell调用d函数(Ipython或类似的)?我看着pyd,但似乎已经过时了.

python shell d pyd

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

strtol表现不尽如人意,c

#include<limits.h>
#include<errno.h>

long output;

errno = 0;
output = strtol(input,NULL,10);
printf("long max = %ld\n",LONG_MAX);
printf("input = %s\n",input);
printf("output = %ld\n",output);
printf("direct call = %ld\n",strtol(input,NULL,10));
if(errno || output >= INT_MAX || output <= INT_MIN) {
    printf("Input was out of range of int, INT_MIN = %d, INT_MAX = %d\n",INT_MIN,INT_MAX);
    printf("Please input an integer within the allowed range:\n");
}
Run Code Online (Sandbox Code Playgroud)

当上面的代码输入{'1','2','3','4','5','6','7','8','9','0的输入数组时", '1'}

我得到的输出:

long max = 9223372036854775807
input = 12345678901
output = -539222987
direct call = 3755744309
Run Code Online (Sandbox Code Playgroud)

发生了什么... strtol似乎正在遭受溢出但没有设置errno

c string int strtol

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

标签 统计

d ×2

arrays ×1

c ×1

constructor ×1

dynamic-arrays ×1

int ×1

pyd ×1

python ×1

shell ×1

string ×1

strtol ×1