小编120*_*arm的帖子

_malloca 和 malloc 有什么区别?

我正在使用 Visual Studio 静态代码分析来分析我的代码。我使用malloc大小初始化了指针,然后通过循环尝试访问它。在那里我收到了 C++ 警告代码 6085的警告。

当我将实现从 更改为 时,malloc错误_malloca就消失了。

有人可以解释一下C++ 中的malloc和之间有什么区别吗?_malloca

c++

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

为什么 cmp 指令中的参数顺序很重要?

我想知道为什么cmp指令需要一定的参数顺序条件。

例如,我已经尝试了这两种方法。

  1. cmpl %eax, $'A'
  2. cmpl $'A', %eax

第一行返回错误,表示操作数类型不匹配。第二行工作得很好。

我浏览了 Intel IA-32 手册,但它无法回答我的问题。它只是说参数 1 和参数 2 之间的减法,而不是每个参数应该具有的类型。

我想知道为什么第一行代码返回的操作数类型不匹配,而第二行却没有。

x86 assembly att

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

在以下示例中无法理解cmpsb

我正在关注有关操作系统的教程,并且遇到了以下块代码,该块代码根据变量“ ImageName”检查磁盘上的文件名。

我的困惑源于push di前一行rep cmpsb

    mov       cx, WORD [bpbRootEntries]
    mov       di, 0x0200
.LOOP:
    push      cx
    mov       cx, 0x000B
    mov       si, ImageName
    push      di
    rep  cmpsb
    pop       di
    je        LOAD_FAT
    pop       cx
    add       di, 0x0020
    loop      .LOOP
    jmp       FAILURE
Run Code Online (Sandbox Code Playgroud)

我找到的cmpsb状态文档“对于传统模式,将地址DS:(E)SI上的字节与地址ES:(E)DI上的字节进行比较。状态标志会相应地设置。” di在此调用之前推送不意味着我总是要与一个空值进行比较吗?该代码有效,因此我显然会误解某些东西,但是我能找到的每篇文档都暗示该代码不起作用。

x86 assembly x86-16

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

为什么在这里需要这个花括号?谁能解释我为什么会这样?

我正在编写代码以制作屏幕截图并将其保存为JPEG文件类型。我找到了这段代码,但是我不明白为什么之后删除花括号时它给我一个错误 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

完整代码:

void gdiscreen()
{
    using namespace Gdiplus;
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
    {
        HDC scrdc, memdc;
        HBITMAP membit;
        scrdc = ::GetDC(0);
        int Height = GetSystemMetrics(SM_CYSCREEN);
        int Width = GetSystemMetrics(SM_CXSCREEN);
        memdc = CreateCompatibleDC(scrdc);
        membit = CreateCompatibleBitmap(scrdc, Width, Height);
        HBITMAP hOldBitmap = (HBITMAP)SelectObject(memdc, membit);
        BitBlt(memdc, 0, 0, Width, Height, scrdc, 0, 0, SRCCOPY);
        Gdiplus::Bitmap bitmap(membit, NULL);
        CLSID clsid;
        GetEncoderClsid(L"image/jpeg", &clsid);
        bitmap.Save(L"screen.jpeg", &clsid);
        SelectObject(memdc, hOldBitmap);
        DeleteObject(memdc);
        DeleteObject(membit);
        ::ReleaseDC(0, scrdc);
    }
    GdiplusShutdown(gdiplusToken);
}
Run Code Online (Sandbox Code Playgroud)

有人可以向我解释为什么我需要花括号吗?

当我移除花括号时,出现以下错误:

Exception produced …
Run Code Online (Sandbox Code Playgroud)

c++ gdi+ visual-studio

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

重载运算符*(乘法)返回不同的结果

我创建class Matrix并重载operator*了矩阵乘法。在操作员内部,计算是正确的,但返回的结果与此不同。

我尝试将此功能从朋友功能更改为方法,但得到的结果相同。此外,我重载了+,-等运算符,它们可以正常工作

#include <iostream>
#include <math.h>

template<typename T> class Matrix;
template<typename T> Matrix<T> operator * (const Matrix<T>&, const Matrix<T>&);

template <typename T> class Matrix
{
public:
    T *arr = nullptr;
    int r, c;
    friend Matrix<T> operator * <> (const Matrix<T>&, const Matrix<T>&);

    Matrix(T *a, int r, int c)  //parametrized constructor
    {
        this->arr = a;
        this->r = r;
        this->c = c;
    }

    void Print()
    {
        for(int i=0; i<r; i++)
        {
            std::cout<<"|";
            for(int j=0; j<c; j++)
            { …
Run Code Online (Sandbox Code Playgroud)

c++

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

向量&lt;pair &lt;double,double &gt;&gt;给定问题

#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<pair<double, double> > Vec; //cords vector (0.0,0.0)/(x,y)
typedef pair<double, double> Punto; //single coord

int main()
{
    int x;
    cout << "cuants vertex?" << endl;
    cin >> x;
    Vec V[x]; // Declare vector of pairs as long as user wants
    Punto P;
    for (int i = 0; i < V.size(); i++) { //fill vector with coords
        cout << "Introdueix coordenada numero: " << i;
        cout << "x: ";
        cin >> P.first; …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

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

返回二叉搜索树某一层节点数的函数

我必须创建一个函数getNodesatLevel来返回某个级别的节点数,但是,我收到了“可能到达 void 函数的结尾”错误。这是针对二叉搜索树的,我需要为此函数使用递归。

int TreeType::getNodesAtLevel(TreeNode * &node, int level, ItemType * mainArr)
{
    int currentLevel = 0;
    int NodeCount = 1;

    if(currentLevel == level)
    {
        NodeCount++;
        return NodeCount;
    }
    else if(currentLevel != level)
    {
        currentLevel++;

        if(node->left != NULL)
            getNodesAtLevel(node->left, level, mainArr);

        if(node->right != NULL)
            getNodesAtLevel(node->right, level, mainArr);
    }
}
Run Code Online (Sandbox Code Playgroud)

c++

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

在 Visual Studio 中检测到堆损坏,但程序在另一个 C 编译器中运行良好:为什么?

我尝试寻找这个问题,但找不到任何答案。我编写了一个程序,用链表实现堆栈及其操作。该程序在 C Web IDE 上编译并完美运行。

当我在 Visual Studio 中运行该程序时,它失败并给出以下错误:

调试错误!程序:C:\Users...我的文件路径检测到堆损坏:在 0x011058C8 处的正常块(#78)之后。CRT 检测到应用程序在堆缓冲区末尾后写入内存。

由于我的代码在其他地方运行良好,这一定是我使用 Visual Studio 的方式存在问题。有任何想法吗?我是 Visual Studio 的新手,恐怕这可能是愚蠢的事情,但我似乎无法弄清楚。

我在下面包含了我的代码,请注意,失败是由 Visual Studio 中的 pop() 函数引起的。

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node* next;
};

struct Node* top = NULL; //initialize head

void push(int x);
void push(int x) {
    struct Node* add = (struct Node*)malloc(sizeof(struct Node*));
    add->data = x;
    add->next = top; //make add point to what top (head) points to (old 1st)
    top = add; …
Run Code Online (Sandbox Code Playgroud)

c heap-corruption visual-studio-2019

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

拥有可以指向或引用已在堆栈上分配的不同类型数据的映射的现代方法

使用原始指针,可以这样实现:

#include <iostream>
#include <string>
#include <map>

using namespace std;

class base {
public:
    virtual ~base(){}
};

class derived1 : public base {
public:
    virtual ~derived1(){}
    derived1(const int& other) : val(other) {}
    int val;
};

class derived2 : public base {
public:
    virtual ~derived2(){}
    derived2(const float& other) : val(other) {}
    float val;
};


int main()
{
    derived1 dataA = 4;
    derived2 dataB = 3.0f;

    std::map<std::string, base*> mapOfPointersToData; //Needs to be a pointer because it can be of type deribed1 or …
Run Code Online (Sandbox Code Playgroud)

c++ reference smart-pointers

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

由于无效的堆栈指针,无法调用程序集页面错误处理程序

当我的页面错误处理程序中断被调用时(它应该挂起系统),在调用之前有一些变量被推送到堆栈中。我启用了虚拟内存,当我设置一个无效的堆栈指针(esp)并且 int14 处理程序被调用时,它会立即导致另一个页面错误等等。我应该如何解决这种情况?

我的 int14 代码:

isr14:
    ; interrupt handler for isr14
    jmp $
    iretd
Run Code Online (Sandbox Code Playgroud)

导致它中断的代码:

mov esp, 0x1000 ; 0x1000 is not mapped in the VM directory
push dword 'A'
jmp $
Run Code Online (Sandbox Code Playgroud)

我的 IDT 表的部分:

irq14:
    dw isr14
    dw 0x0008
    db 0x00
    db 10101110b
    dw 0x0000

irq15:
........
Run Code Online (Sandbox Code Playgroud)

x86 assembly kernel interrupt virtual-machine

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