Basic Infos
- [ x] This issue complies with the issue POLICY doc.
- I have read the documentation at readthedocs and the issue is not addressed there.
- I have tested that the issue is present in current master branch (aka latest git).
- I have searched the issue tracker for a similar issue.
- If there is a stack dump, I have decoded it.
- I have filled out all fields below.
Platform
- Hardware: [ESP-12] [NodeMCU v09/v1]
- Core Version: [2.6.3]
- Development Env: [Arduino IDE 1.8.12]
- Operating System: [Windows|MacOS]
Settings in IDE
Below does not matter its a toolchain problem
- Module: [Generic ESP8266 Module|Nodemcu|]
- Flash Mode: [dout]
- Flash Size: [4MB/1MB]
- lwip Variant: [v1.4|v2 Lower Memory|Higher Bandwidth]
- Reset Method: [ck|nodemcu]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz|160MHz]
- Upload Using: [SERIAL]
- Upload Speed: [115200|other] (serial upload only)
Problem Description
The foliowing (condensed for reproduction) code compiles fine on all Arduinos (UNO/pro/Nano…) avr 1.8.2 and the ESP32 core 1.04. It fails to compile on the esp8266 core. It seems to be a compiler related tool chain problem.
Setup: Basic *.ino file with include to the header file and the following header with a simple class definition arraytest.h
#ifndef ARRAYTEST_H_
#define ARRAYTEST_H_
/******************************************************************************************************/
#define MAX_A_FUNCTIONS 29
/******************************************************************************************************/
/** @brief Data associated to each entry in the A roster.*/
class A_Manager {
private:
uint8_t _aKey ; /**< The numeric place (0-10 = slot number) of the part on the roster (=unique ID) */
const char* _typeField; /** part - Added for more flexibility */
const char* _subTypeField; /** Added for more flexibility for part - active for the selected part */
char _functionMap[MAX_A_FUNCTIONS + 1] = ""; /** < Current status of the functions: 0 for Off, 1 for On - Length of array is MAX_A_FUNCTIONS */
public:
char functionMap[MAX_A_FUNCTIONS + 1] = "";
A_Manager(uint8_t , const char* , const char*, char []);
~A_Manager();
uint8_t getAKey() const ;
};
/***************************************** CPP part *************************************************/
A_Manager::A_Manager(uint8_t aKey, const char* typeField = "APart", const char* subTypeField = "ASubPart", char functionMap[MAX_A_FUNCTIONS+1] = {''})
{
aKey = _aKey;
typeField = _typeField;
subTypeField = _subTypeField;
strcpy (functionMap, _functionMap);
for (uint8_t functionID = 0; functionID <= MAX_A_FUNCTIONS; functionID++) {
functionMap[functionID] = '0';
}
}
A_Manager::~A_Manager() {}
uint8_t A_Manager::getAKey() const {
return _aKey;
}
#endif /* ARRAYTEST_H_ */
Debug Messages
In file included from C:DevArduinoESP8266_Dev_Exampleserror_array_classerror_array.ino:1:0:
c:XXXXarduino_build_XXXXsketcharraytest.h: In constructor 'A_Manager::A_Manager(uint8_t, const char*, const char*, char*)':
arraytest.h:22:151: error: array used as initializer
A_Manager::A_Manager(uint8_t aKey, const char* typeField = "APart", const char* subTypeField = "ASubPart", char functionMap[MAX_A_FUNCTIONS+1] = {''})
arraytest.h:22:151: error: array used as initializer
exit status 1
array used as initializer
Seems like a similar error the gnu compilers had until 5.03
c++11 is activated in platform.txt
There is no option to change the program as it works in production on all other named platforms for a year.
If you need more Info -glad to help
ratatyq 3 / 3 / 1 Регистрация: 16.09.2015 Сообщений: 121 |
||||||||
1 |
||||||||
21.01.2016, 16:56. Показов 18748. Ответов 3 Метки нет (Все метки)
Вот собственно сама ошибка: «array must be initialized with a brace-enclosed initializer»
draw.cpp
__________________
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
21.01.2016, 16:56 |
3 |
Croessmah Don’t worry, be happy 17781 / 10545 / 2036 Регистрация: 27.09.2012 Сообщений: 26,516 Записей в блоге: 1 |
||||
21.01.2016, 17:12 |
2 |
|||
1 |
3 / 3 / 1 Регистрация: 16.09.2015 Сообщений: 121 |
|
21.01.2016, 17:56 [ТС] |
3 |
Croessmah, Спасибо помогло, вот только не пойму если мы сделали 4-ех значный массив то почему мы указали всего две скобки([][]) заместо четырех([][][][])?
0 |
0 / 0 / 0 Регистрация: 29.03.2019 Сообщений: 1 |
|
30.03.2019, 10:35 |
4 |
Массив двухзначный так-то был изначально
0 |
Fails to compile, but should work: struct A { char x[4]; A():x("bug") { } }; Error i get is: "main.cpp:3: error: array used as initializer"
(In reply to comment #0)
> Fails to compile, but should work:
>
> struct A {
> char x[4];
> A():x("bug") { }
> };
>
> Error i get is:
>
> "main.cpp:3: error: array used as initializer"
>
Why do you think it should work?
For example, the following equivalent code is invalid as well:
char x [4] ("bug");
(In reply to comment #1)
> (In reply to comment #0)
> > Fails to compile, but should work:
> >
> > struct A {
> > char x[4];
> > A():x("bug") { }
> > };
> >
> > Error i get is:
> >
> > "main.cpp:3: error: array used as initializer"
> >
>
> Why do you think it should work?
> For example, the following equivalent code is invalid as well:
>
> char x [4] ("bug");
>
This code is equivalent and is valid. At least, I don't see the Standard forbidding it. GCC is the only compiler I tested (comeau/edg, clang) that rejects it.
(In reply to comment #2)
> (In reply to comment #1)
> > (In reply to comment #0)
> > > Fails to compile, but should work:
> > >
> > > struct A {
> > > char x[4];
> > > A():x("bug") { }
> > > };
> > >
> > > Error i get is:
> > >
> > > "main.cpp:3: error: array used as initializer"
> > >
> >
> > Why do you think it should work?
> > For example, the following equivalent code is invalid as well:
> >
> > char x [4] ("bug");
> >
>
> This code is equivalent and is valid. At least, I don't see the Standard
> forbidding it. GCC is the only compiler I tested (comeau/edg, clang) that
> rejects it.
I'm not actually sure anymore about the validity of this code. One can make a point about the initializer not being a mere string literal.
At least the draft n3126 makes a difference of this, in that an initializer like "({a, b, c})" is not regarded as a braced-init-list, but rather as a parenthesized expression-list where the initializer list is handed as one argument. So I'm unsure whether an initializer like `("foo")` should be regarded as a string literal or not.
I think I will send an issue report about this.
(In reply to comment #3)
> (In reply to comment #2)
> > (In reply to comment #1)
> > > (In reply to comment #0)
> > > > Fails to compile, but should work:
> > > >
> > > > struct A {
> > > > char x[4];
> > > > A():x("bug") { }
> > > > };
> > > >
> > > > Error i get is:
> > > >
> > > > "main.cpp:3: error: array used as initializer"
> > > >
> > >
> > > Why do you think it should work?
> > > For example, the following equivalent code is invalid as well:
> > >
> > > char x [4] ("bug");
> > >
> >
> > This code is equivalent and is valid. At least, I don't see the Standard
> > forbidding it. GCC is the only compiler I tested (comeau/edg, clang) that
> > rejects it.
>
> I'm not actually sure anymore about the validity of this code. One can make a
> point about the initializer not being a mere string literal.
>
> At least the draft n3126 makes a difference of this, in that an initializer
> like "({a, b, c})" is not regarded as a braced-init-list, but rather as a
> parenthesized expression-list where the initializer list is handed as one
> argument. So I'm unsure whether an initializer like `("foo")` should be
> regarded as a string literal or not.
>
> I think I will send an issue report about this.
Subsequent discussion with Jason showed that this is covered by 8.5p13:
The form of initialization (using parentheses or =) is generally
insignificant, but does matter when the initializer or the entity
being initialized has a class type;
As this is an array, the text in the Standard in general has to be interpreted that a "=" or a "(..)" initializer are equivalent, unless otherwise stated.
So this is indeed a GCC bug (both that it rejects the member initialization and the parenthesized non-member initialization).
Confirmed.
Mine.
Author: paolo Date: Wed Jun 4 22:30:39 2014 New Revision: 211248 URL: http://gcc.gnu.org/viewcvs?rev=211248&root=gcc&view=rev Log: /cp 2014-06-04 Paolo Carlini <paolo.carlini@oracle.com> PR c++/43453 * typeck.c (cp_build_modify_expr): Handle array of characters initialized by a string literal. * decl.c (check_initializer): Handle parenthesized string literal as initializer. * typeck2.c (store_init_value): Remove redundant check. /testsuite 2014-06-04 Paolo Carlini <paolo.carlini@oracle.com> PR c++/43453 * g++.dg/init/pr43453.C: New. Added: trunk/gcc/testsuite/g++.dg/init/pr43453.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c trunk/gcc/cp/typeck.c trunk/gcc/cp/typeck2.c trunk/gcc/testsuite/ChangeLog
Fixed for 4.10.0. |
Массив ошибок используется в качестве инициализатора, и я не знаю ошибки
Ошибка в конструкторе класса manejo.cpp, ошибка «manejo.cpp:3:16: ошибка: массив используется как инициализатор», и я не знаю, где эта ошибка.
к сообщению прилагается исходный код класса manejo.hpp и реализация manejo.cpp, спасибо
#include "manejo.hpp"
manejo::manejo(){}
manejo::~manejo(){}
ГЭС
#ifndef __MANEJO_HPP
#define _MANEJO_HPP
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
using std::vector;
using std::string;
class manejo{
private:
char cadena[128]="";
vector <string> linea;
long cantidadPD = 0;
vector <string> palabras;
int Creglas = 0;
vector <string> reglas;
long atoi(const char *str);
public:
manejo();
~manejo();
void EstablecerVariables();
int StoInt (string numero);
};
#endif
Эта медитация
char cadena[128]="";
не является допустимым в традиционном С++ (это допустимо в С++ 11, но очевидно, что вы его не используете, потому что иначе вы не получили бы эту ошибку). Удалить =""
, инициализируйте элементы данных в своем конструкторе, а не в своем классе. Например
manejo::manejo()
{
cadena[0] = '';
...
}
ответ дан 13 окт ’13, 16:10
Не тот ответ, который вы ищете? Просмотрите другие вопросы с метками
c++
or задайте свой вопрос.