小编izl*_*lin的帖子

假设指向同一变量的两个指针是非法的/UB,为什么 C 编译器不能优化更改 const 指针的值?

最近我偶然发现了 Rust 和 C 之间的比较,它们使用以下代码:

bool f(int* a, const int* b) {
  *a = 2;
  int ret = *b;
  *a = 3;
  return ret != 0;
}
Run Code Online (Sandbox Code Playgroud)

在 Rust(相同的代码,但使用 Rust 语法)中,它生成以下汇编代码:

    cmp      dword ptr [rsi], 0 
    mov      dword ptr [rdi], 3 
    setne al                    
    ret
Run Code Online (Sandbox Code Playgroud)

使用 gcc 时,它会产生以下结果:

   mov      DWORD PTR [rdi], 2   
   mov      eax, DWORD PTR [rsi]
   mov      DWORD PTR [rdi], 3        
   test     eax, eax                  
   setne al                           
   ret
Run Code Online (Sandbox Code Playgroud)

文本声称 C 函数不能优化第一行,因为ab可能指向相同的数字。在 Rust 中这是不允许的,因此编译器可以将其优化掉。

现在我的问题:

该函数采用一个const …

c strict-aliasing undefined-behavior rust

62
推荐指数
3
解决办法
2974
查看次数

在 .NET Core 中使用 System.Windows

我在 Visual Studio 2019 中有一个项目,正在从 .NET Framework 4.6 迁移到 .NET Core 3.1。

我使用 Microsoft 的指南来移植我的项目,如下所述。我运行了可移植性分析器,它表明该项目是 100% 可移植的。

但对 System.Windows 的所有依赖都不再起作用。例如我使用System.Windows.Rect. 在官方文档中明确指出它可用于.NET Core 3.1。

然而,在代码中,它用“无法找到类型或命名空间名称‘Rect’(您是否缺少 using 指令或程序集引用?)”标记 Rect,并在顶部用消息“ using System.WindowsUsing 指令是”标记我的灰色。不必要”。

此错误适用于我的代码中的许多内容,例如System.Windows.ResourceDictionary, System.Windows.Application.Current, System.Windows.Point, ...

因此,由于某些原因,我似乎无法使用System.Windows,即使使用本身似乎工作正常。

System.Windows我在 NuGet 包管理器中搜索并用谷歌搜索,但找不到任何东西。

所以这是我的问题:如何System.Windows在 Visual Studio 2019 的 .NET Core 3.1 项目中使用?我目前的猜测是,我需要手动包含该程序集WindowsBase.dll,但在我的安装目录 ( C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional) 中我只能找到一个C:\Program Files (x86)\Microsoft …

c# .net-core visual-studio-2019 .net-core-3.1

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

使用AES-256和C语言中的openssl计算CBC-MAC

我想用openssl计算给定明文的CBC-MAC.我有以下明文(hexdump):

hexdump -C example.txt
00000000  4d 41 43 73 20 61 72 65  20 76 65 72 79 20 75 73  |MACs are very us|
00000010  65 66 75 6c 20 69 6e 20  63 72 79 70 74 6f 67 72  |eful in cryptogr|
00000020  61 70 68 79 21 20 20 20  20 20 20 20 20 20 20 20  |aphy!           |
Run Code Online (Sandbox Code Playgroud)

如果我使用openssl的命令行函数,我得到以下解决方案:

openssl aes-256-cbc -in example.txt -K 8000000000000000000000000000000000000000000000000000000000000001 -e -iv 00 | hexdump -C
00000000  e8 e9 …
Run Code Online (Sandbox Code Playgroud)

c openssl cryptography aes cbc-mac

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