gpt4 book ai didi

c++ - "Type name does not allow storage class to be specified"将值作为参数传递时出错

转载 作者:行者123 更新时间:2023-12-02 18:56:52 25 4
gpt4 key购买 nike

我一直在为 6502 编写模拟器的基础知识。我有一个函数,我想用它来设置给定寄存器的零和负标志。该函数包含在名为 CPU 的结构中。

我的代码目前如下所示:

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

typedef uint8_t BYTE;
typedef uint16_t WORD;
typedef uint32_t DWORD;

struct CPU {
BYTE SP; // stack pointer
WORD PC; // program counter

BYTE A, X, Y; // registers

// some more registers, flags, etc.

void SetStatusFlags(BYTE register) {
Z = (register == 0);
N = (register & 0b10000000) > 0;
}

// some other functions that call this one...
};

这会导致错误:

error: type name does not allow storage class to be specified
Z = (register == 0);
^

它还会导致有关括号的其他错误,尽管 this C++ linter似乎没有检测到此类事情的任何问题。

只有当我向函数传递参数时才会发生这种情况。如果我写这样的东西:

void different() {
Z = (A == 0);
N = (A & 0b10000000) > 0;
}

没有发生错误。

最佳答案

register 是一个(已弃用的)关键字。为变量选择一个不同的名称。

参见:

关于c++ - "Type name does not allow storage class to be specified"将值作为参数传递时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66093874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com