我正在尝试编译一些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
阅读其他人的代码,我看到了与语法类似的东西:
int main(void) {
static int attr[] = {FOO, BAR, BAZ, 0};
/* ... */
}
Run Code Online (Sandbox Code Playgroud)
这是一个错误还是有一些理由声明变量main static?据我了解,它static可以防止链接并保持调用之间的价值.因为它在函数内部只执行后者,但main只调用一次,所以我没有看到这一点.这是否会修改某些编译行为(例如,防止其优化不存在)?
我通过谷歌找到的二次/三次贝塞尔曲线代码主要通过将线细分为一系列点并用直线连接它们来实现.光栅化发生在行算法中,而不是在bézier算法中.像Bresenham这样的算法逐像素地工作以栅格化一条线,并且可以进行优化(参见Po-Han Lin的解决方案).
什么是二次贝塞尔曲线算法,像线像算法一样逐像素地工作,而不是绘制一系列点?
我有一个扩展实体的类播放器:
玩家:
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)
但它显然确实有必要的论据.这里发生了什么?谢谢!
假设我编译并运行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()?换句话说,子进程是否包含对于永远不会被它执行的父代码,反之亦然?或者编译器是否可以对此进行优化?
我正在编写一个小型库来与 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) 我一直在摆弄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) 假设我有一个文件在每一行都有一个单行(笑话).我想通过我发现它们多么有趣来对笑话进行排序.我的第一个想法是实现任何排序算法(最好是尽可能少的比较)并让比较算法接受我的输入; 我只是坐在那里,选择它给我的每一对笑话中哪一个更有趣.
有一个问题.我的笑话偏好不是总订单.它缺乏传递性.例如,我可能认为B在呈现它时比A更有趣,并且C比B更有趣,但是当以某种方式呈现A和C时,我发现A比C更有趣.如果">"意味着"比有趣, "这意味着C> B和B> A不不意味着C> A.所有排序算法正确性取决于此.
但它似乎仍然存在应该是排序笑话的列表中,这样的一个在顶部的算法最优先于其他的笑话,和一个在底部至少优于其他的笑话,即使有个别例外.
我不知道如何谷歌这个.有这种偏好排序的算法吗?这里的答案不适用,因为它强制用户的偏好是可传递的.
我在玩 C++ 并对此感到困惑:
\ncppreference.com表示非类型模板参数必须是结构类型,而文字类类型是结构类型的一个示例。然后它说\xe2\x80\x9cLiteral 类型是 constexpr 变量的类型,它们可以从 constexpr 函数\xe2\x80\x9d构造、操作和返回(强调我的)。(事实上, constexpr 函数的返回类型必须是文字类型。)
\n所以我的理解是可以从 constexpr 函数返回暗示是文字类型暗示是结构类型暗示可以用作非类型模板参数。
\n但它似乎std::optional 可以从 constexpr 函数返回(bar如下),但不能用作非类型模板参数(foo紧接如下)。这是怎么回事?
#include <optional>\ntemplate <std::optional<int> Z> int foo(int x) { return x; }\nint main() { return foo<std::optional{0}>(0); }\nRun Code Online (Sandbox Code Playgroud)\n这会导致编译器错误(GCC 和 clang 分别)
\n\n\n<source>:2:30: 错误:\'std::Optional\' 不是模板非类型参数的有效类型,因为它不是结构性的
\n
\n<translation>:2:30: 错误:非类型模板参数的类型“std::Optional”不是结构类型 …
我正在学习汇编,当然我正在尝试经典的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 … 我有两个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) 有没有办法fmt输出多列格式的文本(手册页中似乎没有任何关于此的内容,所以我对此表示怀疑)?fmt如果没有,是否有类似但可以输出多列文本的命令?
使用以下命令将现有文件附加到另一个文件很容易cat:cat file1 >> file2
有时我读过人们写的内容," cat除非你连接两个文件,否则不要使用." 这是明智的.如果它只采用一个论证,那就不需要猫:cat file | xargs program更糟糕的是xargs program < file.
那么如何在没有cat的情况下将文件附加到另一个文件?既不工作< file1 >> file2也不>> file2 < file1工作.如果我必须召集一个程序来做这件事,那么正统的做法是什么?
c ×5
algorithm ×2
bash ×2
fork ×2
linux ×2
optimization ×2
append ×1
arguments ×1
assembly ×1
bezier ×1
bios ×1
c++ ×1
clone ×1
cmd ×1
command-line ×1
concurrency ×1
constructor ×1
crt ×1
directory ×1
file ×1
format ×1
framebuffer ×1
gcc ×1
inheritance ×1
interrupt ×1
java ×1
memory ×1
nasm ×1
non-type-template-parameter ×1
pixelformat ×1
raster ×1
shell ×1
sorting ×1
static ×1
text ×1
transitivity ×1
user-input ×1
x86 ×1