'_circularBuffer' does not name a type

In the start of my code I have:

#define SCREEN_WIDTH 128  // OLED display width, in pixels
int _circularBuffer[SCREEN_WIDTH];  //fast way to store values
int _curWriteIndex = 0;             // tracks where we are in the circular buffer

In Setup I have:

for (int i = 0; i < SCREEN_WIDTH; i++) {
    _circularBuffer[i] = 24;  //Start with graph at midpoint.
  }

And in the Loop I have:

_circularBuffer[_curWriteIndex++] = Distance;

And it is in that last line where I get the error:
'_circularBuffer' does not name a type.
This code has been working for weeks but when I went into it to clean it up some, I started getting this and I don't know what to do about it. My edits had nothing to do with the code I have shown here...unless they did.

Any suggestions would be appreciated.

edit: "Distance" was declared at the start of my code:

int unsigned Distance;

Post the code. Or a minimum sketch that has the same problem.

This is fine, so.

# define SCREEN_WIDTH 128  // OLED display width, in pixels

int _circularBuffer[SCREEN_WIDTH];  //fast way to store values
int _curWriteIndex = 0;             // tracks where we are in the circular buffer
int Distance;

void setup() {
  for (int i = 0; i < SCREEN_WIDTH; i++) {
    _circularBuffer[i] = 24;  //Start with graph at midpoint.
  }
}

void loop() {
  _circularBuffer[_curWriteIndex++] = Distance;
}

a7

Thanks alto. I copied that and it runs fine. (???)

So we done? You put those lines back into your sketch and away you went?

Or is your real sketch still with that error, which obvsly must be caused by what we never have seen yet.

a7

And this topic is a textbook example of why you post the whole sketch!

# define SCREEN_WIDTH 128  // OLED display width, in pixels

int _circularBuffer[SCREEN_WIDTH];  //fast way to store values
int _curWriteIndex = 0;             // tracks where we are in the circular buffer
int Distance;

void setup() {
  for (int i = 0; i < SCREEN_WIDTH; i++) {
    _circularBuffer[i] = 24;  //Start with graph at midpoint.
  }
}

void loop() {
}

  _circularBuffer[_curWriteIndex++] = Distance;
arduino-cli compile -b arduino:avr:uno --warnings all --output-dir /home/me/tmp --no-color (in directory: /home/me/Documents/sketchbook/Uno_R3/test)
/home/me/Documents/sketchbook/Uno_R3/test/test.ino:16:3: error: '_circularBuffer' does not name a type
   _circularBuffer[_curWriteIndex++] = Distance;
   ^~~~~~~~~~~~~~~
Used platform Version Path
arduino:avr   1.8.3   /home/me/.arduino15/packages/arduino/hardware/avr/1.8.3
Error during build: exit status 1
Compilation failed.

Is that your error? Do you see the problem?

2 Likes

No. I'm sorry but I don't. That's why I'm here, to ask someone with more experience than I have to offer some suggestions as to why this error may be present. If you don't have enough info to make an educated guess, then that is the answer.

And do you really want me to post all 349 lines of my code?

Yes. If you still have the error, there is no other way.

349 lines is nothing.

@van_der_decken made the error happen with a tiny sketch. I made it go away with a tiny sketch. This appears to be without your skill level at this time. You are here for help - this is probably a simple matter and as you see, nothing whatsoever to do with anything you've posted.

If you read much on these fora, you will see ppl regularly posting huge amounts of code, and we ask them to try to bake it down.

349 lines is baked enough.

If it helps, it took me some time to see the error… I don't seem to see errors I would never make. :expressionless:

a7

I do now! I finally found it after using Auto Format and seeing that damn curly bracket standing there all by itself.

What I had done was to comment out an IF statement that I was using to conditionally print some variables and failed to grab the ending bracket for the IF.

Why can't the compiler catch that, rather than laying blame on an untyped thing?

Thank you van der decken and alto.

There is a coding style that places the opening bracket on the line after the if statement, which makes it easier to comment out the if statement.

if (condition)
{
  //statements to be executed
}

It is certainly true that compiler error reporting can get you pointed off the main track.

I dread seeing the red ink after some editing, especially when it says something like your error message reported.

A stray or missing this or that can cause a world of hurt, and a crap ton of essentially useless clues from the compiler.

We may see better error reporting if AI could be harnessed. Don't hold your breath.

In the meantime, make progress through the smallest of steps you can. Good planning and habits help.

Many of my sketches begin as a structural outline of functions that don't do anything other than maybe printing a message about what they will do, one day.

Mostly I work on a section of code I can see - if an error starts happening, the cause , it has to be in front of me.

And of course using a standard format and/or the Autoformat tool will make some errors pop what might otherwise have eluded you.

And here I will say if you haven't done, go to the IDE preferences and crank up all warnings and verbosity. Then read and need the red ink for "warnings" about things that are perfectly legal but may also be perfectly not at all what you meant.

Dunno if it would have helped in this case, and I doubt we'll ever be free of needing to crawl hands and knees like through the code looking for WTF is going on.

a7

Yes. The people with more experience, as you put it, have spelled out exactly that in How to get the best out of this forum. That is the answer.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.