小编neb*_*uch的帖子

命令提示符不会将目录更改为另一个驱动器

我正在尝试编译一些java(当前学习java),为此我需要更改命令提示符的目录(使用javac).

C:\...\Admin> cd D:\Docs\Java
C:\...\Admin> cd
C:\...\Admin
Run Code Online (Sandbox Code Playgroud)

它不会更改目录.我再次尝试使用引号:

C:\...\Admin> cd "D:\Docs\Java"
C:\...\Admin>
Run Code Online (Sandbox Code Playgroud)

同样,它不会更改目录.我究竟做错了什么?

directory command-line cmd command-prompt command-line-interface

294
推荐指数
8
解决办法
44万
查看次数

为什么在main中声明一个静态变量?

阅读其他人的代码,我看到了与语法类似的东西:

int main(void) {
    static int attr[] = {FOO, BAR, BAZ, 0};
    /* ... */
}
Run Code Online (Sandbox Code Playgroud)

这是一个错误还是有一些理由声明变量main static?据我了解,它static可以防止链接并保持调用之间的价值.因为它在函数内部只执行后者,但main只调用一次,所以我没有看到这一点.这是否会修改某些编译行为(例如,防止其优化不存在)?

c static program-entry-point

10
推荐指数
2
解决办法
2223
查看次数

逐个像素Bézier曲线

我通过谷歌找到的二次/三次贝塞尔曲线代码主要通过将线细分为一系列点并用直线连接它们来实现.光栅化发生在行算法中,而不是在bézier算法中.像Bresenham这样的算法逐像素地工作以栅格化一条线,并且可以进行优化(参见Po-Han Lin的解决方案).

什么是二次贝塞尔曲线算法,像线像算法一样逐像素地工作,而不是绘制一系列点?

algorithm optimization bezier raster

9
推荐指数
2
解决办法
5536
查看次数

Java实际参数与正式参数不匹配,但它们呢?

我有一个扩展实体的类播放器:

玩家:

public class Player extends Entity {
    public Player(char initIcon, int initX, int initY) {
        //empty constructor
    }
...
Run Code Online (Sandbox Code Playgroud)

实体:

public Entity(char initIcon, int initX, int initY) {
        icon = initIcon;
        x = initX;
        y = initY;
    }
...
Run Code Online (Sandbox Code Playgroud)

这几乎是你所期望的,但在编译时我得到一个错误

Player.java:2: error: constructor Entity in class Entity cannot be applied to the given types:
    public Player(char initIcon, int initX, int initY)
required: char,int,int
found: no arguments
reason: actual and formal argument lists differ in length
Run Code Online (Sandbox Code Playgroud)

但它显然确实有必要的论据.这里发生了什么?谢谢!

java inheritance constructor arguments

6
推荐指数
2
解决办法
2522
查看次数

fork()是否复制了父级的所有内存?

假设我编译并运行fork()的教科书示例.

#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>

int main(void)
{
        pid_t pid;
        pid = fork();

        if (pid == -1)
                return 1;

        if (pid == 0)
                puts("From child process.");
        else
                puts("From parent process.");

        return 0;
}
Run Code Online (Sandbox Code Playgroud)

来自if (pid == 0)语句的两个分支的代码是否得到了fork()?换句话说,子进程是否包含对于永远不会被它执行的父代码,反之亦然?或者编译器是否可以对此进行优化?

c memory concurrency optimization fork

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

Linux 帧缓冲区像素位域通用实现

我正在编写一个小型库来与 Linux 的帧缓冲区抽象接口。我的所有显卡都使用相同的像素格式(每个通道一个八位字节,四个通道,BGRA 排序),因此到目前为止,库仅采用这种格式。但是,如果我希望该库在任何 Linux 帧缓冲区上工作,帧缓冲区 API 提供了我必须使用的像素格式数据。你不需要知道帧缓冲区是如何工作的来回答这个问题(我希望),只需要一些我不熟悉的小技巧。这是我的标题中提供的像素格式信息:

/* Interpretation of offset for color fields: All offsets are from the right,
 * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you
 * can use the offset as right argument to <<). A pixel afterwards is a bit
 * stream and is written to video memory as that unmodified.
 *
 * For pseudocolor: offset and length should be the same for all color
 * components. Offset specifies the position …
Run Code Online (Sandbox Code Playgroud)

c linux bit-manipulation framebuffer pixelformat

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

Linux 克隆调用的最小堆栈大小?

我一直在摆弄clone调用,我注意到不同子线程堆栈分配的三种不同结果。以下演示分配了一个n字节大的堆栈,其中n作为参数传递,然后尝试克隆。

foo.c :

#define _GNU_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <errno.h>

int child(void *arg)
{
    (void)arg;
    write(STDOUT_FILENO, "carpe momentum\n", 15);
    return 0;
}

int main(int argc, char **argv)
{
    long stacksize;
    pid_t pid;
    void *stack;

    if (argc < 2)
        return 1;

    errno = 0;
    stacksize = strtol(argv[1], NULL, 0);
    if (errno != 0)
        return 1;

    stack = malloc(stacksize);
    if (stack == NULL)
        return 1;

    pid = clone(child, stack + stacksize, 0, NULL); …
Run Code Online (Sandbox Code Playgroud)

c linux fork clone

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

针对不一致(非传递)人类偏好的排序算法

假设我有一个文件在每一行都有一个单行(笑话).我想通过我发现它们多么有趣来对笑话进行排序.我的第一个想法是实现任何排序算法(最好是尽可能少的比较)并让比较算法接受我的输入; 我只是坐在那里,选择它给我的每一对笑话中哪一个更有趣.

有一个问题.我的笑话偏好不是总订单.它缺乏传递性.例如,我可能认为B在呈现它时比A更有趣,并且C比B更有趣,但是当以某种方式呈现A和C时,我发现A比C更有趣.如果">"意味着"比有趣, "这意味着C> B和B> A不意味着C> A.所有排序算法正确性取决于此.

但它似乎仍然存在应该是排序笑话的列表中,这样的一个在顶部的算法优先于其他的笑话,和一个在底部至少优于其他的笑话,即使有个别例外.

我不知道如何谷歌这个.有这种偏好排序的算法吗?这里的答案不适用,因为它强制用户的偏好是可传递的.

sorting algorithm user-input transitivity

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

结构类型和 contexpr 函数返回类型之间的区别

我在玩 C++ 并对此感到困惑:

\n

cppreference.com表示非类型模板参数必须是结构类型,而文字类类型是结构类型的一个示例。然后它说\xe2\x80\x9cLiteral 类型是 constexpr 变量的类型,它们可以从 constexpr 函数\xe2\x80\x9d构造、操作和返回(强调我的)。(事实上​​, constexpr 函数的返回类型必须是文字类型。)

\n

所以我的理解是可以从 constexpr 函数返回暗示是文字类型暗示是结构类型暗示可以用作非类型模板参数。

\n

但它似乎std::optional 可以从 constexpr 函数返回(bar如下),但不能用作非类型模板参数(foo紧接如下)。这是怎么回事?

\n
#include <optional>\ntemplate <std::optional<int> Z> int foo(int x) { return x; }\nint main() { return foo<std::optional{0}>(0); }\n
Run Code Online (Sandbox Code Playgroud)\n

这会导致编译器错误(GCC 和 clang 分别)

\n
\n

<source>:2:30: 错误:\'std::Optional\' 不是模板非类型参数的有效类型,因为它不是结构性的

\n
\n
\n

<translation>:2:30: 错误:非类型模板参数的类型“std::Optional”不是结构类型 …

c++ non-type-template-parameter

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

通过bios中断获取字符串

我正在学习汇编,当然我正在尝试经典的0x10 bios中断.我看过的资源显示lodsb用于打印字符串,所以要理解操作码我试图模仿它的行为.这适用于lodsb,但不是我拥有的.我究竟做错了什么?:

start:
    mov ah, 0Eh ;for bios interrupt
    mov si, text_string ;set source index to begining of text_string

.repeat:
    ;I'm trying to emulate the behavior of lodsb to learn how it works:
    mov al, [si] ;put character at si in al register
    add si, 1 ;increment source index

    cmp al, 0 ;if the character is a zero (end of the string)
    je done ;end execution

    int 10h ;bios interrupt to put character on screen
    jmp …

x86 assembly interrupt bios nasm

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

如何避免C运行时(crt*.o)垃圾

我有两个C源文件

foo1.c:

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    puts("hello world");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

并且foo2.c:

#include <stdlib.h>
#include <stdio.h>

void _start(void)
{
    puts("hello world");
    exit(0);
}
Run Code Online (Sandbox Code Playgroud)

我在我的i386 GNU/Linux平台上编译它们:

$ #compile foo1
$ cc -o foo1 foo1.c
$ #compile foo2
$ cc -S foo2.c
$ as -o foo2.o foo2.s
$ ld -o foo2 -dynamic-linker /lib/i386-linux-gnu/ld-linux.so.2 -lc foo2.o
$ #notice that crt1.o and others are missing
Run Code Online (Sandbox Code Playgroud)

从用户的角度来看,输出的可执行文件做同样的事情.

$ ./foo1
hello world
$ ./foo2
hello world
Run Code Online (Sandbox Code Playgroud)

但他们是不同的:

$ wc -c …
Run Code Online (Sandbox Code Playgroud)

c gcc crt

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

多列 fmt

有没有办法fmt输出多列格式的文本(手册页中似乎没有任何关于此的内容,所以我对此表示怀疑)?fmt如果没有,是否有类似但可以输出多列文本的命令?

format bash shell text text-manipulation

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

在没有cat的bash中将文件附加到文件

使用以下命令将现有文件附加到另一个文件很容易cat:cat file1 >> file2

有时我读过人们写的内容," cat除非你连接两个文件,否则不要使用." 这是明智的.如果它只采用一个论证,那就不需要猫:cat file | xargs program更糟糕的是xargs program < file.

那么如何在没有cat的情况下将文件附加到另一个文件?既不工作< file1 >> file2也不>> file2 < file1工作.如果我必须召集一个程序来做这件事,那么正统的做法是什么?

bash file append

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