我编写了以下使用new. 但问题是 clang 拒绝该程序,而 gcc 和 msvc 接受它。我的问题是哪个编译器就在这里?
struct C{
C(int);
};
int main() {
C *ptr{new C[]{1}}; //clang rejects but gcc accepts
}
Run Code Online (Sandbox Code Playgroud)
铿锵 说:
<source>:6:21: error: no matching constructor for initialization of 'C'
6 | C *ptr{new C[]{1}}; //clang rejects but gcc accepts
| ^
<source>:3:4: note: candidate constructor not viable: requires 1 argument, but 0 were provided
3 | C(int);
| ^ ~~~
<source>:2:8: note: candidate constructor (the implicit copy constructor) not viable: requires …Run Code Online (Sandbox Code Playgroud) 我不太明白括号里的内容;NetLogo 要么说我缺少括号,要么需要括号。每当我尝试添加或删除括号时,它只会说另一个括号已损坏。单纯的代码是行不通的。有人帮忙!
globals [
initial-trees
burned-trees ]
breed [fires fire]
to setup
clear-all
set-default-shape turtles "square"
ask patches with [(random-float 100) < density]
[ set pcolor green ]
[ plants ]
ask patches with [pxcor = min-pxcor]
[ ignite ]
set initial-trees count patches with [pcolor = green]
set burned-trees 0
reset-ticks
end
to go
if not any? turtles
[ stop ]
ask fires
[ ask neighbors4 with [pcolor = green]
if random 100 < 50 [ignite]
[ ask neighbors4 …Run Code Online (Sandbox Code Playgroud) 如何在运行时通过代码访问Delphi项目中表单的DFM资源?
背景:我希望能够在运行时解析表单的 DFM,以根据需要创建 HTML 和其他表示形式。当然,我可以在构建项目之前解析它们并创建额外的资源。但当它们被编译到软件中并在运行时使用时,我相信它们也应该可以在代码中以某种方式访问。
我目前使用 Delphi 11,很快就会使用 Delphi 12。
delphi embedded-resource dfm delphi-11-alexandria delphi-12-athens
这是我当前的代码:
// Yes, the missing single quotation mark is intentional
static void replace_punctuation(char *s, size_t len)
{
static const unsigned char punctuation[] = ".,;:!?\"()[]{}-";
for (size_t i = 0; i < len; ++i) {
if (memchr(punctuation, s[i], sizeof punctuation - 1)) {
s[i] = ' ';
}
}
}
Run Code Online (Sandbox Code Playgroud)
对程序进行分析(cachegrind/Kcachegrind)(在启用优化的情况下编译,-O2)后,发现这是一个瓶颈。
s不是以 null 结尾的字符串,因此strpbrk()不能使用。
如何对其进行优化?
我有一个具有以下粗略结构的大型数据集,其中多个列共享前缀:
dataset <- data.frame(a1 = c(1:10), a2 = c(11:20),b1=c(21:30),b2=c(31:40))
Run Code Online (Sandbox Code Playgroud)
我想创建新列,其中包含共享前缀的每组列的行总和,以便它最终看起来像这样
a1 a2 b1 b2 a_sum b_sum
1 1 11 21 31 12 52
2 2 12 22 32 14 54
3 3 13 23 33 16 56
4 4 14 24 34 18 58
5 5 15 25 35 20 60
6 6 16 26 36 22 62
7 7 17 27 37 24 64
8 8 18 28 38 26 66
9 9 19 29 39 28 68
10 …Run Code Online (Sandbox Code Playgroud) 我正在为学校开发一个程序,用户可以选择一个单选按钮来显示总统的图像。但是,单击按钮时我无法显示图像。我不知道哪里出了问题,我需要一些帮助。其他一切都很好。我需要进行任何编辑吗?
package com.example.imagedisplay;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import java.io.File;
public class PresidentImageDisplay extends Application {
@Override
public void start(Stage primaryStage) {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Select Presidents Folder");
File selectedDirectory = directoryChooser.showDialog(primaryStage);
if (selectedDirectory != null) {
File[] imageFiles = selectedDirectory.listFiles();
if (imageFiles != null && imageFiles.length >= 5) {
ImageView[] presidentImageViews = new ImageView[5];
ToggleGroup toggleGroup = new ToggleGroup();
HBox radioBox = …Run Code Online (Sandbox Code Playgroud) 我知道这是未定义的行为(这里已经有其他问题在谈论这种情况):
int const i = 0;
int const& j = i;
const_cast<int&>(j) = 8;
Run Code Online (Sandbox Code Playgroud)
不过,我想这不是吧?
int i = 0;
int const& j = i;
const_cast<int&>(j) = 8;
Run Code Online (Sandbox Code Playgroud)
如果我没记错的话,UB 只修改const对象,而不管您用来引用它的引用的限定符如何。因此,删除对最初不是 const 的对象的引用的 const 限定符,然后写入它就可以了,对吗?
我在这里读到以下内容:
“Python stdlib 模块random包含伪随机数生成器,其许多方法与 中可用的方法类似Generator。”
然而,Python 模块“random”的第一个链接的 URL 指向 Numpy 的 random.random 文档,而不是某些通用的 Python 库。
这个链接是错误的还是我只是不明白文档在这里想说的内容?我对 Python 中生成随机数的所有不同选项感到非常困惑。我现在数了一下至少有四个:
numPy 单例 RandomState 对象
numPy RandomState 对象
numPy 生成器对象
Python 的一般随机功能显然是这样的。
任何见解都是非常受欢迎的。
我使用的框架已经在 CentOS 7 上运行了多年。我们正在将其迁移到 RHEL 8,但一些单元测试失败了。其中一个特别涉及从 std::runtime_error 上的 What() 返回垃圾。我创建了一个非常简单的例子来重复这个问题。它适用于 CentOS7,但不适用于 RHEL 8。代码如下:
#include <sstream>
#include <iostream>
const char * getString() {
std::ostringstream oss;
oss << "some stuff to return" << std::endl;
std::cout << "value to return: " << oss.str().c_str() << std::endl;
return oss.str().c_str();
}
int
main(int argc, char ** argv) {
std::string value = getString();
std::cout << "value returned: " << value << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
CentOS7 的输出是:
[user@localhost ~]$ ./a.out
value to return: some stuff to return …Run Code Online (Sandbox Code Playgroud) 这是一个简短的程序,运行时会出现段错误。即使在迂腐的层面上,它也不会发出关于 clang 的警告。
#include <stdio.h>
#include <stdlib.h>
typedef struct object {
int type;
} object;
void write(object *obj) {
switch (obj->type) {
case 1:
break;
}
}
int main(void) {
printf("hi");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在 x86 Linux 上似乎不会发生崩溃,但我在 aarch64 Android 上。
$ gcc --version
clang version 17.0.6
Target: aarch64-unknown-linux-android24
Thread model: posix
InstalledDir: /data/data/com.termux/files/usr/bin
$ uname -a
Linux localhost 5.10.177-android13-4-00003-ga7208022a7ea-ab10815828 #1 SMP PREEMPT Fri Sep 15 16:40:54 UTC 2023 aarch64 Android
Run Code Online (Sandbox Code Playgroud)
使用 gdb 跟踪它看起来printf最终会调用write,但我现在不知道会发生这种情况。
这看起来像是一个编译器错误,但我可以很好地编译和运行其他程序。如果我删除printf …