variable or field <...> declared void

I'm getting this error for the following code:

void BUZZ_PlayTune1(buzzTune_t tune) {
  if(buzzPlayListIndex < BUZZ_TUNE_PLAYLIST_SIZE) {                         // if there is free room in the playlist
    if(tune < BUZZ_TUNE_ARRAY_SIZE) {                                       // if the tune is valid
      buzzPlayList[buzzPlayListIndex++] = tune;                             // add tune to the playlist
      buzzer.active = true;                                                 // play the tune
    }
  }
}

I usually get this error when I have a mismatch between curly brackets somewhere else in the code, but that's not the case. When I replace my code with this one the error goes away:

void BUZZ_PlayTune2() {
  buzzTune_t tune = BUZZ_TUNE_SOS;
  if(buzzPlayListIndex < BUZZ_TUNE_PLAYLIST_SIZE) {                         // if there is free room in the playlist
    if(tune < BUZZ_TUNE_ARRAY_SIZE) {                                       // if the tune is valid
      buzzPlayList[buzzPlayListIndex++] = tune;                             // add tune to the playlist
      buzzer.active = true;                                                 // play the tune
    }
  }
}

The only difference is that I don't use "buzzTune_t tune" as an argument. For some reason it doesn't like the argument.
The buzzTune_t is a typedef enum like this:

typedef enum {
  BUZZ_TUNE_CUSTOM = 0,                                                     // user-defined bit pattern
  BUZZ_TUNE_1_SHORT,                                                        // 1 short beep - 200 ms sound, 100 ms silence
  BUZZ_TUNE_1_LONG,                                                         // 1 long beep - 500 ms sound
  BUZZ_TUNE_2_SHORT,                                                        // 2 short beeps - each 200 ms sound, 100 ms silence
  BUZZ_TUNE_2_LONG,                                                         // 2 long beeps - 500 ms sound, 200 ms silence
  BUZZ_TUNE_3_SHORT,                                                        // 3 short beeps - each 200 ms sound, 100 ms silence
  BUZZ_TUNE_3_LONG,                                                         // 3 long beeps - 500 ms sound, 200 ms silence
  BUZZ_TUNE_SOS,                                                            // SOS - dididi-dahdahdah-dididi
} buzzTune_t;

The caret under the offending statement in the error message points to the argument:

Buzzer:77:21: error: variable or field 'BUZZ_PlayTune1' declared void
 void BUZZ_PlayTune1(buzzTune_t tune) {
                     ^

I can't figure out what is wrong with it.

Arduino IDE version 1.8.13

Mmmmh....
I created a separate sketch with only the "offending" code and the related definitions/declarations and that compiles without problems. I'm at a loss...
Curly brackets (or any other kind of issue in the surrounding code) can't be the problem, otherwise I should get a similar error when I use "BUZZ_PlayTune2()" u.s.o. "BUZZ_PlayTune1(buzzTune_t tune)" ?

It looks like the function void BUZZ_PlayTune1(buzzTune_t tune) was prototyped somewhere as:

void BUZZ_PlayTune1( void );

but you are trying to pass it a parameter of type buzzTune_t.

Can you post/attach your whole code?

My guess is that the "buzzTune_t" enum is not declared before the first function and, therefore, the automatically generated prototype (just before the first function) is in a place where "buzzTune_t" is not defined.

I found this on StackExchange:
"the environment searches for function definitions within your main sketch file and creates declarations (prototypes) for them. These are inserted after any comments or pre-processor statements (#includes or #defines), but before any other statements (including type declarations). This means that if you want to use a custom type as a function argument, you should declare it within a separate header file."

Your auto-gen prototype is void BUZZ_PlayTune1( void ); because the preprocessor hasn't seen your typedef yet.

johnwasser:
My guess is that ...

Of course, if @gilbert54 would post a complete code instead of snippets, nobody would have to guess.

@ Blackfin: nope, I did a search on "BUZZ_PlayTune" in all files and only the lines with "BUZZ_PlayTune1" and "BUZZ_PlayTune2" in the Buzzer sketch are found.

@ johnwasser: "buzzTune_t" is declared in Buzzer.h and the header file is definitely included in the code file (I'd have tons of other errors if that would be the problem). I also tried moving the typedef to the code file, but the result is the same.

@SteveMann: see my response to johnwasser. All other typedefs work fine.

@gfvalvo: tried to include the Buzzer header and code files, but it' too much text for a post. I have attached Buzzer.ino and Buzzer.h. I don't think that you want to review the other 5000 lines of code. Anyway, everything compiled nicely before I added the buzzer stuff.

Buzzer.h (2.26 KB)

Buzzer.ino (8.85 KB)

gilbert54:
@ Blackfin: nope, I did a search on "BUZZ_PlayTune" in all files and only the lines with "BUZZ_PlayTune1" and "BUZZ_PlayTune2" in the Buzzer sketch are found.

@ johnwasser: "buzzTune_t" is declared in Buzzer.h and the header file is definitely included in the code file (I'd have tons of other errors if that would be the problem). I also tried moving the typedef to the code file, but the result is the same.

@SteveMann: see my response to johnwasser. All other typedefs work fine.

@gfvalvo: tried to include the Buzzer header and code files, but it' too much text for a post. I have attached Buzzer.ino and Buzzer.h. I don't think that you want to review the other 5000 lines of code. Anyway, everything compiled nicely before I added the buzzer stuff.

I'm surprised you're able to call any of the functions in Buzzer.ino from another .ino or .cpp file without having extern prototypes in Buzzer.h.

If you add prototypes to the end of your include:

.
.
.
typedef struct {
  bool    active;                                                     // true when buzzer is engaged
  uint8_t pinNumber;                                                  // GPIO pin number for buzzer OUT
  uint8_t pinValue;                                                   // ON or OFF
  buzzAction_t action;                                                // SOUND, SILENCE, WAIT4NEXT
  uint8_t bitIndex;                                                   // index in tune bit pattern
} buzzer_t;

//prototypes
extern void BUZZ_PlayTune1(buzzTune_t);
extern void BUZZ_InitBuzzerMonitor();
extern void BUZZ_BuzzerMonitor();

#endif  /* BUZZER_H */

to your include do you see different results?

Don't need to do that. The Arduino IDE creates the function prototypes automatically. Anyway, my other code does not yet contain those calls. That's still "TODO".
I only need to create prototype manually for ISR functions and for functions with optional arguments.
But I'll give it a shot...

gilbert54:
@SteveMann: see my response to johnwasser. All other typedefs work fine.

We're trying to help you, but IF YOU DON'T PROVIDE THE COMPLETE SKETCH, how can anyone try to duplicate your problem?

Problem solved. Including the Buzzer.h file in the main ino file did the trick.
That header file was included in the Buzzer code file, but apparently that's not enough, even though the main ino file doesn't use any of the custom types defined in that header file.

Adding a prototype for function BUZZ_PlayTune1(buzzTune_t) is not needed.

Thanks to everyone for their help.

"buzzTune_t" is a variable and not a type; A type name must be declared between "enum" and "{".