scriptor6
scriptor6

Reputation: 226

"Type name does not allow storage class to be specified" error when passing value as argument

I have been writing the foundations of an emulator for a 6502. I have a function that I want to use to set the zero and negative flags for a given register. This function is contained in a struct called CPU.

My code currently looks like this:

#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...
};

This causes an error:

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

It also causes other errors concerning parentheses, although this C++ linter doesn't seem to detect any problems with such things.

This only happens if I pass the function a parameter. If I write something like this:

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

No errors occur.

Upvotes: 2

Views: 564

Answers (1)

John Kugelman
John Kugelman

Reputation: 361729

register is a (deprecated) keyword. Pick a different name for the variable.

See:

Upvotes: 5

Related Questions