Downloaded code won't compile - no type

Using downloaded code (which others have compiled successfully), I get this error:

ISO C++ forbids declaration of 'prog_char' with no type [-fpermissive]
    2 | size_t sendProgmem(WiFiClient client, const prog_char (&str)[N])

Is this a case where older code (+5 years) is no longer compatible with latest IDE (Arduino 1.8.15)?

Is some library not installed? If so, how would I discover where this should be being called from?

Specific code that's causing the problem:

template<size_t N>
size_t sendProgmem(WiFiClient client, const prog_char (&str)[N])
{
  return sendProgmem(client, str, N);
}

size_t sendProgmem(WiFiClient client, const prog_char progmem[], size_t size) {
    size_t maxSize=2920; // this seems to be the max that write() will ever actually send
    size_t sent=0;

    while(sent < size) {
      size_t sendSize = (maxSize < (size - sent)) ? maxSize : (size - sent);
      sent += client.write(progmem+sent, sendSize); // write() may send less than you asked it to
    }
    return sent;
}

try with

template<size_t N>
size_t sendProgmem(WiFiClient client, const char(&str)[N])
{
  return sendProgmem(client, str, N);
}

size_t sendProgmem(WiFiClient client, const char progmem[], size_t size) {
    size_t maxSize=2920; // this seems to be the max that write() will ever actually send
    size_t sent=0;

    while(sent < size) {
      size_t sendSize = (maxSize < (size - sent)) ? maxSize : (size - sent);
      sent += client.write(progmem+sent, sendSize); // write() may send less than you asked it to
    }
    return sent;
}

It's not really about the Arduino IDE version. It's about the compilation toolchain version. This code was written for an old version of the AVR toolchain. If you were to use that old toolchain with the latest Arduino IDE version, the prog_char typedef would be treated just as it was when the code was written.

The reason it is somewhat related to the IDE version is because the Arduino IDE comes with a bundled copy of the Arduino AVR Boards platform, including its AVR toolchain. The latest version of that platform is included with each Arduino IDE release, so there is a correlation between the AVR toolchain typically in use and the Arduino IDE version. However, it is possible to install other versions of the platform, or other platforms entirely, and when you do that the bundled copy will no longer be in use. So there isn't really such a strong connection between the two things.

Good news, bad news! Good news is the compiler gets past that error. So many thanks for that.

And you'll have already guessed what I'm going to say now ... the NEXT compiler error:

'WebSocketsServer' does not name a type
WebSocketsServer webSocket = WebSocketsServer(81);

that means that WebSocketsServer was not declared... what are you trying to compile?

Its a project from instructables.com (https://www.instructables.com/The-Light-Clock-IoT/)

is that the source code.?

seems he embedded some libraries like the WebSocketsServer

it seems also it's a PlatformIO program

Yes, that's it. Author mentions he's updated a couple of other modules: NeoPixel and NTP related (links are in that page a few lines down)

it seems to be a PlatformIO program. Are you using the Arduino IDE?

Yes I am. v1.8.15 on Windows 10/64

that repo is not meant for the Arduino IDE. it's organised for PlatformIO

That would explain a lot. I'll download that and see where I end up.

There is NO way I'd ever have worked that out on my own. Many, many thanks. I'll try the Platform IO later and report back. Thanks again for your persistence and help.

have fun, that's what matters :wink:

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