小编MLa*_*paj的帖子

将uint32_t转换为int32_t,然后进行比较

我无法理解如何比较两个int,其中一个是unsigned int32,另一个是signed int32。让我们考虑这个简单的程序:

#include <stdint.h>

int main()
{
    uint32_t a1 = UINT32_MAX;
    int32_t b1 = (int32_t)a1;

    if (a1 == b1)
        printf("Equal");
    else
        printf("Not equal");

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

在这种情况下,a1超出了有符号的32位整数范围,因此正如我在调试时已确认的那样,在将其强制转换后,它b1等于-1。但是,它仍然显示“等于”,而这些值显然并不相同。是什么原因造成的?

c stdint

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

使用 clang-tidy 分析嵌入式 GCC 项目

我正在尝试使用 clang-tidy 来解析由 arm-none-eabi-g++ 编译的项目。

不幸的是,clang-tidy 无法找到编译器头,即使给出了它们的包含路径。

我的compile_commands.json是

  [   
    {
    "directory": "C:/LMA/repo/clang-tidy",
    "arguments": [
      "arm-none-eabi-c++",
      "-IC:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1",
      "-IC:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1/arm-none-eabi/arm/v5te/hard",
      "test.cpp"
    ],
    "file": "./test.cpp"   } ]
Run Code Online (Sandbox Code Playgroud)

示例 test.cpp 文件是:

#include <cstdint>
#include <cstdlib>

int test()
{
  int temp;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

Clang-tidy 显示错误:

C:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1\cstdlib:75:15: error: 'stdlib.h' file not found [clang-diagnostic-error]
#include_next <stdlib.h>
Run Code Online (Sandbox Code Playgroud)

因此,它正确地找到并包含 cstdlib,但是无法找到位于完全相同的文件夹中的 stdint.h。更令人恼火的是,它不包括 stdlib.h,即使我添加

-include C:/nxp/MCUXpressoIDE_11.2.1_4149/ide/tools/arm-none-eabi/include/c++/9.2.1/stdlib.h 到编译器参数以强制预包含。

非常感谢任何如何解决此问题的建议。

c++ llvm clang-tidy

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

我什么时候应该在 Python 中使用类和 self 方法?

我一直在尝试编写一个 Python 程序来根据与 4 个锚点的距离计算点位置。我决定将其计算为 4 个圆的交点。

我有一个关于不是算法的问题,而是关于在此类程序中使用类的问题。我真的没有太多的 OOP 经验。真的有必要在这里使用类还是至少以任何方式改进程序?

这是我的代码:

import math

class Program():
    def __init__(self, anchor_1, anchor_2, anchor_3, anchor_4, data):
        self.anchor_1 = anchor_1
        self.anchor_2 = anchor_2
        self.anchor_3 = anchor_3
        self.anchor_4 = anchor_4



    def intersection(self, P1, P2, dist1, dist2): 
        PX = abs(P1[0]-P2[0])               
        PY = abs(P1[1]-P2[1])
        d = math.sqrt(PX*PX+PY*PY)   

        if d < dist1+ dist2 and d > (abs(dist1-dist2)):

            ex = (P2[0]-P1[0])/d
            ey = (P2[1]-P1[1])/d

            x = (dist1*dist1 - dist2*dist2 + d*d) / (2*d)
            y = math.sqrt(dist1*dist1 - x*x)

            P3 = …
Run Code Online (Sandbox Code Playgroud)

python oop

3
推荐指数
2
解决办法
2541
查看次数

标签 统计

c ×1

c++ ×1

clang-tidy ×1

llvm ×1

oop ×1

python ×1

stdint ×1