I am having trouble initializing a string in a class (foo at the end of the code below). This is my header file...
#ifndef A2I_CHESS_H
#define A2I_CHESS_H
#include <Arduino.h>
#include <HTTPClient.h>
#include <A2I_commands.h>
#include <Apple2Idiot.h>
/* Apple II <-> ESP Commands */
#define CHESS_GET_AI_MOVE 20
#define CHESS_GET_GAME_STATUS 22
#define CHESS_GET_BOARD 23
#define CHESS_MAKE_MOVE 21
/* Responses */
#define CHESS_INVALID_MOVE 123
#define CHESS_VALID_MOVE 124
#define MAX_GAME_SIZE 110 * 4 // This is probably not enough, but it's fine for development.
// https://chess.stackexchange.com/questions/2506/what-is-the-average-length-of-a-game-of-chess
// times four because one move is "e7e5"
class Chess {
public:
byte appId = APP_CHESS; // This is "registered" with A2I_commands.h which is part of Apple2Idiot.h
// This id is sent from the Apple to the ESP to tell the esp what app
// is currently active. The main loop of the ESP sketch then knows to use
// this class to respond to incoming commands from the Apple.
char game_string[MAX_GAME_SIZE]; // This is probably not enough, but it's fine for development.
char game_status[25];
void init(Apple2Idiot *a2ip, HTTPClient *httpp);
byte handleCommand(byte command);
byte validateMove(String move_string);
private:
Apple2Idiot *a2i;
HTTPClient *http;
const char api_entry_point[32] = "http://chess-api.herokuapp.com";
const char foo[] = "hello world";
};
#endif
... and here is the error ...
Arduino: 1.8.15 (Linux), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, None"
In file included from /home/equant/projects/apple_ii/apple2idiot/examples/chess/a2i_chess.cpp:4:0:
a2i_chess.h:46:28: error: initializer-string for array of chars is too long [-fpermissive]
const char foo[] = "hello world";
^
In file included from /home/equant/projects/apple_ii/apple2idiot/examples/chess/chess.ino:14:0:
a2i_chess.h:46:28: error: initializer-string for array of chars is too long [-fpermissive]
const char foo[] = "hello world";
^
/home/equant/projects/apple_ii/apple2idiot/examples/chess/a2i_chess.h: In constructor 'Chess::Chess()':
a2i_chess.h:23:7: error: initializer-string for array of chars is too long [-fpermissive]
class Chess {
^
/home/equant/projects/apple_ii/apple2idiot/examples/chess/chess.ino: At global scope:
/home/equant/projects/apple_ii/apple2idiot/examples/chess/chess.ino:25:25: note: synthesized method 'Chess::Chess()' first required here
Chess chess_app = Chess();
^
Multiple libraries were found for "WiFi.h"
Used: /home/equant/.arduino15/packages/esp32/hardware/esp32/1.0.6/libraries/WiFi
Not used: /home/equant/bin/arduino-1.8.15/libraries/WiFi
exit status 1
initializer-string for array of chars is too long [-fpermissive]
I've seen this syntax for initializing a string used in tutorials and in these forums. Is there something about the context of this happening in a header, or a class or under "private:" that makes this illegal? Thanks for any help.