问题列表 - 第318071页

涉及数组 clang 警告的 _Generic 控制表达式的左值转换错误?

给定以下宏,用于_Generic确定参数是否是数组(而不是指针):

#include <stdio.h>

#define IS_ARRAY(T)   \
  _Generic( &(T)[0],  \
    typeof(T) : 0,    \
    default   : 1     \
  )

int a[2];
int *p = a;

int main() {
  printf( "IS_ARRAY(a) = %d\n", IS_ARRAY(a) );
  printf( "IS_ARRAY(p) = %d\n", IS_ARRAY(p) );
}
Run Code Online (Sandbox Code Playgroud)

和:

$ clang --version
clang version 17.0.6
$ clang -std=c2x a.c
Run Code Online (Sandbox Code Playgroud)

我得到:

a.c:15:33: warning: due to lvalue conversion of the controlling expression, association of type 'typeof ((a))' (aka 'int[2]') will never be selected because it is of array …
Run Code Online (Sandbox Code Playgroud)

c clang

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

集合表达式没有目标类型

使用C# 12 的新集合表达式,我无法执行以下操作:

if (["blue", "red", "foo"].Any((x) =>
{
    ...
})) 
Run Code Online (Sandbox Code Playgroud)

它给出了 CS9172 编译器错误“集合表达式没有目标类型”。["blue", "red", "foo"]我必须采用new[] { "blue", "red", "foo" }-- C# 12 之前的方式,而不是,它不必指定类型。

显然,集合表达式仅包含一种类型。是否有技术原因导致编译器无法确定类型?如果可能的话,这将是使用该新功能的一种非常简洁且有用的方式。

.net c# .net-8.0 c#-12.0

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

无法在 Ubuntu 22.04 上安装 MongoDB 7.0

我正在按照官方指南在 Ubuntu 上安装 MongoDB 社区版。

逐步执行命令后:

(1)导入包管理系统使用的公钥。

从终端安装 gnupg 和curl(如果它们尚不可用):

sudo apt-get install gnupg curl

要从https://pgp.mongodb.com/server-7.0.asc导入 MongoDB 公共 GPG 密钥,请运行以下命令:

curl -fsSL https://pgp.mongodb.com/server-7.0.asc | \
    sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
    --dearmor
Run Code Online (Sandbox Code Playgroud)

(2)创建MongoDB的列表文件

为 Ubuntu 22.04 (Jammy) 创建 /etc/apt/sources.list.d/mongodb-org-7.0.list 文件:

echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.com/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
Run Code Online (Sandbox Code Playgroud)

(3) 重新加载本地包数据库

发出以下命令重新加载本地包数据库:

sudo apt-get update
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

curl -fsSL https://pgp.mongodb.com/server-7.0.asc | \
    sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
    --dearmor
Run Code Online (Sandbox Code Playgroud)

ubuntu mongodb

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

用于保存 std::byte 的 C++ 类

有没有保存到文件std::bytes 中的 C++ 类?我已经使用了std::ofstream,但是需要强制转换才能执行它:

std::byte bt{ 1 };
std::ofstream ofs{};
ofs.write(reinterpret_cast<const char*>(bt), 1);
Run Code Online (Sandbox Code Playgroud)

你看:reinterpret_cast<const char*>?是否有其他std::byte无需任何强制转换即可保存的 C++ 类?

c++ c++17

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

下面计算简单移动平均线的函数有什么问题?

我编写了下面的函数,以便根据所需的 SMA 公式查找 csv 文件的 SMA,但是,我的公式有问题,我无法弄清楚。

def SMA_calculation(t, w):
    s = np.size(t)
    g = np.zeros(s)
    for i in range(0, s):
        if i < w-1:
            g[i] = np.NaN
        else:
            g[i] = np.mean(t[i-w:i])
    return g
Run Code Online (Sandbox Code Playgroud)

python numpy moving-average

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

为什么编译这个Java文件时大小写没有问题?

如果我写一个Java类如下: public class Test {}

...并将其保存在具有相同类名但大小写不同的文件中,如下所示: test.java

...那为什么可以编译成功,如下: javac Test.java?

我认为公共类的名称和它的文件名必须相同,包括 case。我很惊讶我没有收到“文件未找到”错误。我有什么误解吗?

java compiler-errors case-sensitive

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

“forall”如何影响函数签名?

我使用“forall”量词声明了两个函数。其中第一个在签名之前有一个量词,其中包含所有泛型类型参数。第二个使用量词代替每个泛型类型参数的第一个用法。

\n
f :: forall a b c. a -> b -> c -> b -> a\nf a _ _ _ = a\n\ng :: forall a. a ->\n     forall b. b ->\n     forall c. c -> b -> a\ng a _ _ _ = a\n
Run Code Online (Sandbox Code Playgroud)\n

我期望这两个函数是相同的(区别仅在于描述的风格),但以下两个测试告诉我事实并非如此。

\n
w_f :: (forall a b c. a -> b -> c -> b -> a) -> Bool\nw_f _ = True\n\nw_g :: (forall a. a ->\n        forall b. b ->\n        forall c. c …
Run Code Online (Sandbox Code Playgroud)

haskell function signature parametric-polymorphism

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

我正在使用 amazon linux 并尝试在 ec2 中安装 mysql,但我不断收到错误“GPG key a is已经安装”

我目前正在尝试在 ec2 中安装 mysql,但“GPG key”错误不断发生。

- 错误信息

[root ec2-user]# sudo yum install mysql-community-server
Last metadata expiration check: 3:41:39 ago on Thu Jan 25 23:25:24 2024.
Dependencies resolved.
===================================================================================================
 Package                             Arch        Version              Repository              Size
===================================================================================================
Installing:
 mysql-community-server              x86_64      8.0.36-1.el9         mysql80-community       49 M
Installing dependencies:
 mysql-community-client              x86_64      8.0.36-1.el9         mysql80-community      3.4 M
 mysql-community-client-plugins      x86_64      8.0.36-1.el9         mysql80-community      1.4 M
 mysql-community-common              x86_64      8.0.36-1.el9         mysql80-community      556 k
 mysql-community-icu-data-files      x86_64      8.0.36-1.el9         mysql80-community      2.3 M
 mysql-community-libs                x86_64      8.0.36-1.el9         mysql80-community      1.4 M

Transaction Summary
===================================================================================================
Install  6 Packages

Total …
Run Code Online (Sandbox Code Playgroud)

mysql amazon-ec2

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

自定义滚动条(::-webkit-scrollbar)在版本 121.0.6167.86 中不起作用

我今天更新了chrome。现在我的自定义滚动条全部不起作用,请指导我解决此问题。
这是我的自定义CSS

::-webkit-scrollbar-thumb {<br/>
  background-color: rgba(68, 102, 242, 0.15);<br/>
}<br/>

body.dark-only::-webkit-scrollbar-thumb {<br/>
  background-color: rgba(41, 50, 64, 0.52);<br/>
}<br/>

::-webkit-scrollbar {<br/>
  height: 6px;<br/>
  width: 6px;<br/>
}
Run Code Online (Sandbox Code Playgroud)

我搜索谷歌并找不到答案。
希望得到帮助

scrollbar

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

利用大数据优化 cumsum

我正在尝试编写一个代码,从向量中获取每第 7 个累积和值,但使用循环结构运行速度非常慢,因为我的数据太大了。

这是我写的代码。结果是预期的,但正如我所说,它运行得很慢:

for (i in 1:50000) {
  B[i] <- cumsum(A[i:50000])[7]
}
Run Code Online (Sandbox Code Playgroud)

示例:A = 4 1 2 2 6 2 6 6 1 10 5 8 6 9 1

结果必须是:

B[1] = (4+1+2+2+6+2+6) = 23

B[2] = (1+2+2+6+2+6+6) = 25

所以...

谢谢。

loops r cumsum

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