Pregunta:
error: redefinición de ''
user3826856
2014-07-17 00:35:28 UTC
view on stackexchange narkive permalink

Cuando intento compilar el siguiente código,

  int delayTime = 1; int charBreak = 2.1; #include <MemoryFree.h>int rled1 = 1; int rled2 = 2; int rled3 = 3; int rled4 = 4; int rled5 = 5; int gled1 = 6; int gled2 = 7; int gled3 = 8; int gled4 = 9; int gled5 = 10; int bled1 = 11; int bled2 = 12; int bled3 = 13; int bled4 = 14; int bled5 = 15; void setup () {Serial.begin (9600);} int ra [] = {4,288,18464,288,4}; int ga [] = {2,144,9232, 144,2}; int ba [] = {1,72,4616,72,2}; int rb [] = {18724,16644,16644,2080,0}; int gb [] = {9362,8322,8322 , 1040,0}; int bb [] = {4681,4161,4161,520,0}; int rc [] = {2336,16388,16388,2080,0}; int gc [] = {1168,8194, 8194,1040,0}; int bc [] = {584,4097,4097,520,0}; int rd [] = {18724,16388,16388,2336,0}; int gd [] = {9362,8194 , 8194,1168,0}; int bd [] = {4681,4097,4097,584,0}; int re [] = {18724,16644,16644,16388,0}; int ge [] = {9362, 8322,8322,8194,0}; int be [] = {4681,4161,4161,4097,0}; int rf [] = {18724,16640,16640,16384,0}; int gf [] = {9362 , 8320,8320,8192,0}; int bf [] = {4681,4160,4160,4096,0}; int rg [] = {2336,16388,16420,16416,2084}; int gg [] = {1168,8194,8210,8208,1042}; int bg [] = {584,4097,4105,4104,521}; int rh [] = {18724,256,256,256,18724}; int gh [] = {9362,128,128,128,9362}; int bh [] = {4681,64,64 , 64,4681}; int ri [] = {0,16388,18724,16388,0}; int gi [] = {0,8194,9362,8194,0}; int bi [] = {0,4097, 4681,4097,0}; int rj [] = {32,4,16388,18720,16384}; int gj [] = {16,2,8194,9360,8192}; int bj [] = {8,1 , 4097,4680,4096}; int rk [] = {18724,256,2080,16388,0}; int gk [] = {9362,128,1040,8194,0}; int bk [] = {4681, 64,520,4097,0}; int rl [] = {18724,4,4,4,0}; int gm [] = {9362,2,2,2,0}; int bm [] = {4681,1 , 1,1,0}; int rm [] = {18724,2304,36,2304,18724}; int gm [] = {9362,1152,18,1152,9362}; int bm [] = {4681, 576,9,576,4681}; int rn [] = {18724,2304,36,18724,0}; int gn [] = {9362,1152,18,9362,0}; int bn [] = {4681,576 , 9,4681,0}; int ro [] = {2336,16388,16388,2336,0}; int go [] = {1168,8194,8194,1168,0}; int bo [] = {584, 4097,4097,584,0}; int rp [] = {18724,16640,16640,2048,0};
int gp [] = {9362,8320,8320,1024,0}; int bp [] = {4681,4160,4160,512,0}; int rq [] = {2336,16388,16420,2336,36} ; int gq [] = {1168,8194,8210,1168,18}; int bq [] = {584,4097,4105,584.9}; int rr [] = {18724,16640,16672,2052,0 }; int gr [] = {9362,8320,8336,1026,0}; int br [] = {4681,4160,4168,513,0}; int rs [] = {2048,16644,16644,32, 0}; int gs [] = {1024,8322,8322,16,0}; int bs [] = {512,4161,4161,8,0}; int rt [] = {16384,16384,18724,16384 , 16384}; int gt [] = {8192,8192,9362,8192,8192}; int bt [] = {4096,4096,4681,4096,4096}; int ru [] = {18720,4,4, 18720,0}; int gu [] = {9360,2,2,9360,0}; int bu [] = {4680,1,1,4680,0}; int rv [] = {18432,288,4,288 , 18432}; int gv [] = {9216,144,2,144,9216}; int bv [] = {4608,72,1,72,4608}; int rw [] = {18688,36,2304,36, 18688}; int gw [] = {9344,18,1152,18,9344}; int bw [] = {4672,9,576,9,4672}; int rx [] = {16388,2080,256,2080,16388 }; int gx [] = {8194,1040,128,1040,8194}; int bx [] = {4097,520,64,520,4097}; int ry [] = {16388,2080,256,2048,16384} ; int gy [] = {8194,1040,128,1024,8192}; int by [] = {4097,520,64, 512,4096}; int rz [] = {16420,16644,16644,18436,0}; int gz [] = {8210,8322,8322,9218,0}; int bz [] = {4105,4161,4161 , 4609,0}; int reos [] = {0,4,0,0,0}; int geos [] = {0,2,0,0,0}; int beos [] = {0,1, 0.0,0}; int rque [] = {2048,16420,16640,2048,0}; int gque [] = {1024,8210,8320,1024,0}; int bque [] = {512,4105 , 4160,512,0}; int rexcl [] = {0,18692,0,0,0}; int gexcl [] = {0,9346,0,0,0}; int bexcl [] = {0, 4673,0,0,0}; void displayLine (int line) {int myline; myline = línea; if (myline> = 16384) {digitalWrite (rled1, HIGH); myline- = 16384;} else {digitalWrite (rled1, LOW);} if (myline> = 8192) {digitalWrite (gled1, HIGH); myline- = 8192;} else {digitalWrite (gled1, LOW);} if (myline> = 4096) {digitalWrite (bled1, HIGH); myline- = 4096;} else {digitalWrite (bled1, LOW);} if (myline> = 2048) {digitalWrite (rled2, HIGH); myline- = 2048;} else {digitalWrite (rled2, LOW);} if (myline> = 1024) {digitalWrite (gled2, HIGH); myline- = 1024;} else {digitalWrite (gled2, LOW);}
if (myline> = 512) {digitalWrite (bled2, HIGH); myline- = 512;} else {digitalWrite (bled2, LOW);} if (myline> = 256) {digitalWrite (rled3, HIGH); myline- = 256;} else {digitalWrite (rled3, LOW);} if (myline> = 128) {digitalWrite (gled3, HIGH); myline- = 128;} else {digitalWrite (gled3, LOW);} if (myline> = 64) {digitalWrite (bled3, HIGH); myline- = 64;} else {digitalWrite (bled3, LOW);} if (myline> = 32) {digitalWrite (rled4, HIGH); myline- = 32;} else {digitalWrite (rled4, LOW);} if (myline> = 16) {digitalWrite (gled4, HIGH); myline- = 16;} else {digitalWrite (gled4, LOW);} if (myline> = 8) {digitalWrite (bled4, HIGH); myline- = 8;} else {digitalWrite (bled4, LOW);} if (myline> = 4) {digitalWrite (rled5, HIGH); myline- = 4;} else {digitalWrite (rled5, LOW);} if (myline> = 2) {digitalWrite (gled5, HIGH); myline- = 2;} else {digitalWrite (gled5, LOW);} if (myline> = 1) {digitalWrite (bled5, HIGH); myline- = 1;} else {digitalWrite (bled5, LOW);}} void displayChar (char c) {if (c == 'ra') {for (int i = 0; i <5; i ++) {displayLine (ra [i]); delay (delayTime);} displayLine (0);} if (c == 'rb') {for (int i = 0; i <5; i ++) {displayLine (rb [i]); delay ( delayTime);} displayLine (0);} if (c == 'rc') {for (int i = 0; i <5; i ++) {displayLine (rc2 [i]); delay (delayTime);} displayLine (0 );} if (c == 'rd') {for (int i = 0; i <5; i ++) {displayLine (rd [i]); delay (delayTime);} displayLine (0);} if (c = = 're') {for (int i = 0; i <5; i ++) {displayLine (re [i]); delay (delayTime);} displayLine (0);} if (c == 'rf') {for (int i = 0; i <5; i ++) {displayLine (rf [i]); delay (delayTime);} displayLine (0);} if (c == 'rg') {for (int i = 0; i <5; i ++) {displayLine (rg [i]); delay (delayTime);} displayLine (0);} if (c == 'rh') {for (int i = 0; i <5; i ++) {displayLine ( rh [i]); delay (delayTime);} displayLine (0);}
if (c == 'ri') {for (int it = 0; it <5; it ++) {displayLine (ri [it]); delay (delayTime);} displayLine (0);} if (c == 'rj ') {for (int i = 0; i <5; i ++) {displayLine (rj [i]); delay (delayTime);} displayLine (0);} if (c ==' rk ') {for (int i = 0; i <5; i ++) {displayLine (rk [i]); delay (delayTime);} displayLine (0);} if (c == 'rl') {for (int i = 0; i <5; i ++ ) {displayLine (rl [i]); delay (delayTime);} displayLine (0);} if (c == 'rm') {for (int i = 0; i <5; i ++) {displayLine (rm [i ]); delay (delayTime);} displayLine (0);} if (c == 'rn') {for (int i = 0; i <5; i ++) {displayLine (rn [i]); delay (delayTime) ;} displayLine (0);} if (c == 'ro') {for (int i = 0; i <5; i ++) {displayLine (ro [i]); delay (delayTime);} displayLine (0); } if (c == 'rp') {for (int i = 0; i <5; i ++) {displayLine (rp [i]); delay (delayTime);} displayLine (0);} if (c == ' rq ') {for (int i = 0; i <5; i ++) {displayLine (rq [i]); delay (delayTime);} displayLine (0);} if (c ==' rr ') {for (inti = 0; i <5; i ++) {displayLine (rr [i]); delay (delayTime);} displayLine (0);} if (c == 'rs') {for (int i = 0; i <5; i ++) {displayLine (rs [ i]); delay (delayTime);} displayLine (0);} if (c == 'rt') {for (int i = 0; i <5; i ++) {displayLine (rt [i]); delay (delayTime );} displayLine (0);} if (c == 'ru') {for (int i = 0; i <5; i ++) {displayLine (ru [i]); delay (delayTime);} displayLine (0) ;} if (c == 'rv') {for (int i = 0; i <5; i ++) {displayLine (rv [i]); delay (delayTime);} displayLine (0);} if (c == 'rw') {for (int i = 0; i <5; i ++) {displayLine (rw [i]); delay (delayTime);} displayLine (0);} if (c == 'rx') {for ( int i = 0; i <5; i ++) {displayLine (rx [i]); delay (delayTime);} displayLine (0);} if (c == 'ry') {for (int i = 0; i <5 ; i ++) {displayLine (ry [i]); delay (delayTime);} displayLine (0);} if (c == 'rz') {for (int i = 0; i <5; i ++) {displayLine (rz [i]); delay (delayTime);} displayLine (0);}
if (c == 'r!') {for (int i = 0; i <5; i ++) {displayLine (rexcl [i]); delay (delayTime);} displayLine (0);} if (c == ' r? ') {for (int i = 0; i <5; i ++) {displayLine (rques [i]); delay (delayTime);} displayLine (0);} if (c ==' r. ') {for (int i = 0; i <5; i ++) {displayLine (reos [i]); delay (delayTime);} displayLine (0);} if (c == 'ga') {for (int i = 0; i <5; i ++) {displayLine (ga [i]); delay (delayTime);} displayLine (0);} if (c == 'gb') {for (int i = 0; i <5; i ++) {displayLine ( gb [i]); delay (delayTime);} displayLine (0);} if (c == 'gc') {for (int i = 0; i <5; i ++) {displayLine (gc2 [i]); delay (delayTime);} displayLine (0);} if (c == 'gd') {for (int i = 0; i <5; i ++) {displayLine (gd [i]); delay (delayTime);} displayLine ( 0);} if (c == 'ge') {for (int i = 0; i <5; i ++) {displayLine (ge [i]); delay (delayTime);} displayLine (0);} if (c == 'gf') {for (int i = 0; i <5; i ++) {displayLine (gf [i]); delay (delayTime);} displayLine (0);} if (c == 'gg') { para (int i = 0; i <5; i ++) {displayLine (gg [i]); delay (delayTime);} displayLine (0);} if (c == 'gh') {for (int i = 0; i <5; i ++) {displayLine (gh [ i]); delay (delayTime);} displayLine (0);} if (c == 'gi') {for (int it = 0; it <5; it ++) {displayLine (gi [it]); delay (delayTime );} displayLine (0);} if (c == 'gj') {for (int i = 0; i <5; i ++) {displayLine (gj [i]); delay (delayTime);} displayLine (0) ;} if (c == 'gk') {for (int i = 0; i <5; i ++) {displayLine (gk [i]); delay (delayTime);} displayLine (0);} if (c == 'gl') {for (int i = 0; i <5; i ++) {displayLine (gl [i]); delay (delayTime);} displayLine (0);} if (c == 'gm') {for ( int i = 0; i <5; i ++) {displayLine (gm [i]); delay (delayTime);} displayLine (0);} if (c == 'gn') {for (int i = 0; i <5 ; i ++) {displayLine (gn [i]); delay (delayTime);} displayLine (0);} if (c == 'go') {for (int i = 0; i <5; i ++) {displayLine (ir [i]); delay (delayTime);} displayLine (0);}
if (c == 'gp') {for (int i = 0; i <5; i ++) {displayLine (gp [i]); delay (delayTime);} displayLine (0);} if (c == 'gq ') {for (int i = 0; i <5; i ++) {displayLine (gq [i]); delay (delayTime);} displayLine (0);} if (c ==' gr ') {for (int i = 0; i <5; i ++) {displayLine (gr [i]); delay (delayTime);} displayLine (0);} if (c == 'gs') {for (int i = 0; i <5; i ++ ) {displayLine (gs [i]); delay (delayTime);} displayLine (0);} if (c == 'gt') {for (int i = 0; i <5; i ++) {displayLine (gt [i ]); delay (delayTime);} displayLine (0);} if (c == 'gu') {for (int i = 0; i <5; i ++) {displayLine (gu [i]); delay (delayTime) ;} displayLine (0);} if (c == 'gv') {for (int i = 0; i <5; i ++) {displayLine (gv [i]); delay (delayTime);} displayLine (0); } if (c == 'gw') {for (int i = 0; i <5; i ++) {displayLine (gw [i]); delay (delayTime);} displayLine (0);} if (c == ' gx ') {for (int i = 0; i <5; i ++) {displayLine (gx [i]); delay (delayTime);} displayLine (0);} if (c ==' gy ') {for (int yo = 0; i <5; i ++) {displayLine (gy [i]); delay (delayTime);} displayLine (0);} if (c == 'gz') {for (int i = 0; i <5; i ++) {displayLine (gz [ i]); delay (delayTime);} displayLine (0);} if (c == 'g!') {for (int i = 0; i <5; i ++) {displayLine (gexcl [i]); delay ( delayTime);} displayLine (0);} if (c == 'g?') {for (int i = 0; i <5; i ++) {displayLine (gques [i]); delay (delayTime);} displayLine ( 0);} if (c == 'g.') {For (int i = 0; i <5; i ++) {displayLine (geos [i]); delay (delayTime);} displayLine (0);} if ( c == 'ba') {for (int i = 0; i <5; i ++) {displayLine (ba [i]); delay (delayTime);} displayLine (0);} if (c == 'bb') {for (int i = 0; i <5; i ++) {displayLine (bb [i]); delay (delayTime);} displayLine (0);} if (c == 'bc') {for (int i = 0 ; i <5; i ++) {displayLine (bc2 [i]); delay (delayTime);} displayLine (0);} if (c == 'bd') {for (int i = 0; i <5; i ++) { displayLine (bd [i]); delay (delayTime);} displayLine (0);}
if (c == 'be') {for (int i = 0; i <5; i ++) {displayLine (be [i]); delay (delayTime);} displayLine (0);} if (c == 'bf ') {for (int i = 0; i <5; i ++) {displayLine (bf [i]); delay (delayTime);} displayLine (0);} if (c ==' bg ') {for (int i = 0; i <5; i ++) {displayLine (bg [i]); delay (delayTime);} displayLine (0);} if (c == 'bh') {for (int i = 0; i <5; i ++ ) {displayLine (bh [i]); delay (delayTime);} displayLine (0);} if (c == 'bi') {for (int it = 0; it <5; it ++) {displayLine (bi [it ]); delay (delayTime);} displayLine (0);} if (c == 'bj') {for (int i = 0; i <5; i ++) {displayLine (bj [i]); delay (delayTime) ;} displayLine (0);} if (c == 'bk') {for (int i = 0; i <5; i ++) {displayLine (bk [i]); delay (delayTime);} displayLine (0); } if (c == 'bl') {for (int i = 0; i <5; i ++) {displayLine (bl [i]); delay (delayTime);} displayLine (0);} if (c == ' bm ') {for (int i = 0; i <5; i ++) {displayLine (bm [i]); delay (delayTime);} displayLine (0);} if (c ==' bn ') {for (inti = 0; i <5; i ++) {displayLine (bn [i]); delay (delayTime);} displayLine (0);} if (c == 'bo') {for (int i = 0; i <5; i ++) {displayLine (bo [ i]); delay (delayTime);} displayLine (0);} if (c == 'bp') {for (int i = 0; i <5; i ++) {displayLine (bp [i]); delay (delayTime );} displayLine (0);} if (c == 'bq') {for (int i = 0; i <5; i ++) {displayLine (bq [i]); delay (delayTime);} displayLine (0) ;} if (c == 'br') {for (int i = 0; i <5; i ++) {displayLine (br [i]); delay (delayTime);} displayLine (0);} if (c == 'bs') {for (int i = 0; i <5; i ++) {displayLine (bs [i]); delay (delayTime);} displayLine (0);} if (c == 'bt') {for ( int i = 0; i <5; i ++) {displayLine (bt [i]); delay (delayTime);} displayLine (0);} if (c == 'bu') {for (int i = 0; i <5 ; i ++) {displayLine (bu [i]); delay (delayTime);} displayLine (0);} if (c == 'bv') {for (int i = 0; i <5; i ++) {displayLine (bv [i]); delay (delayTime);} displayLine (0);}
if (c == 'bw') {for (int i = 0; i <5; i ++) {displayLine (bw [i]); delay (delayTime);} displayLine (0);} if (c == 'bx ') {for (int i = 0; i <5; i ++) {displayLine (bx [i]); delay (delayTime);} displayLine (0);} if (c ==' by ') {for (int i = 0; i <5; i ++) {displayLine (por [i]); delay (delayTime);} displayLine (0);} if (c == 'bz') {for (int i = 0; i <5; i ++ ) {displayLine (bz [i]); delay (delayTime);} displayLine (0);} if (c == 'b!') {for (int i = 0; i <5; i ++) {displayLine (bexcl [ i]); delay (delayTime);} displayLine (0);} if (c == 'b?') {for (int i = 0; i <5; i ++) {displayLine (bques [i]); delay ( delayTime);} displayLine (0);} if (c == 'b.') {for (int i = 0; i <5; i ++) {displayLine (beos [i]); delay (delayTime);} displayLine ( 0);} delay (charBreak);} void displayString (char * s) {for (int i = 0; i< = strlen (s); i ++) {displayChar (s [i]); }} bucle vacío () {displayString ("sunil"); Serial.print ("freeMemory () ="); Serial.println (freeMemory ());}  

Recibo el siguiente error.

  sketch_jul17b: 63: error: redefinición de 'int gm [ ] 'sketch_jul17b: 60: error:' int gm [5] 'definido previamente heresketch_jul17b: 64: error: redefinición de' int bm [] 'sketch_jul17b: 61: error:' int bm [5] 'definido previamente heresketch_jul17b.ino: En la función 'void displayChar (char)': sketch_jul17b: 139: error: 'rc2' no fue declarado en este ámbito sketch_jul17b: 164: error: 'rques' no fue declarado en este ámbito scopesketch_jul17b: 168: error: 'gc2' no fue declarado en este scopesketch_jul17b: 177: error: 'gl' no fue declarado en este scopesketch_jul17b: 193: error: 'gques' no fue declarado en este scopesketch_jul17b: 197: error: 'bc2' no fue declarado en este scopesketch_jul17b: 206: error: 'bl' no fue declarado en este ámbito .ketch_jul17b: 222: error: 'bques' no fue declarado en este ámbito  

No sé por qué ocurre este error.

Redefinir los nombres de las variables es una gran razón para evitar nombres sin sentido como los que está usando. Utilice nombres como "RedLedPinNumber" y "RedLedCurrentState" y "GreenLedCurrentState" - MUCHO más fácil de recordar si ya creó uno de esos. Las variables ocupan la misma cantidad de memoria independientemente de sus nombres.
Tres respuestas:
#1
+8
Bruno
2015-09-05 17:18:22 UTC
view on stackexchange narkive permalink

Esto también puede suceder si ha guardado una versión del código (por ejemplo, un archivo duplicado para la copia de seguridad) dentro de la carpeta de bocetos actual.

¡No te preocupes, gracias por el comentario! Sabía que esto ayudaría a alguien, ya que es un error fácil de cometer. (Lo hice cuando dupliqué el archivo dentro de la carpeta de bocetos. Esto sería lo mismo que crear una página de pestaña dentro del IDE para que el código esté doblemente definido. Que es el mismo problema que la pregunta original. De ahí el mismo error.
Gracias, Bruno. Curiosamente, este fue mi problema con el ejemplo de una biblioteca descargada que tenía el mismo ejemplo guardado con extensiones .ino y .pde. Eliminó el .pde y funcionó bien.
#2
+3
user2973
2014-07-17 01:11:57 UTC
view on stackexchange narkive permalink

Los primeros errores ocurren porque estás intentando definir una variable con el mismo nombre en el mismo ámbito dos veces, como aquí:

  int gm [] = {9362,2,2, 2,0}; int bm [] = {4681,1,1,1,0}; int rm [] = {18724,2304,36,2304,18724}; int gm [] = {9362,1152,18 , 1152,9362};  

gm se define dos veces, lo que no está permitido.

El otro error ocurre porque está haciendo referencia a variables que nunca declaró como aquí:

  if (c == 'rc') {for (int i = 0; i <5; i ++) {displayLine (rc2 [i]); delay (delayTime);} displayLine (0);}  

rc2 no está definido en ninguna parte.


Además, hay otros problemas con su código:

  int charBreak = 2.1;  

int tipos solo pueden contienen números enteros, por lo que charBreak se establecerá en dos y no en dos puntos uno. Probablemente no quieras usar un float .

En void displayChar (char c) intentas comparar un char con dos caracteres:

  if (c == 'ra') 

Eso no funcionará. El tipo char solo puede contener un solo carácter, por lo que la comparación siempre será falsa. Dos caracteres como este 'ab' entre comillas simples se interpretan como un número de 16 bits. Dos caracteres entre comillas dobles se interpretan como una cadena terminada en nulo:

  char cstring1 [] = "ab"; char cstring2 [] = {'a', 'b', '\ 0 '}; if (strcmp (cstring1, cstring2) == 0) // Las dos cadenas son idénticas  

strcmp devuelve 0 en la coincidencia -.

Muchas gracias por la ayuda con la comparación de personajes. De hecho, estaba atrapado allí.
#3
+2
Chris Stratton
2014-07-17 00:42:27 UTC
view on stackexchange narkive permalink

Tiene una combinación de intentar definir el mismo nombre dos veces, por ejemplo, "gm"

  int gm [] = {9362,2,2,2,0}; int bm [] = {4681,1,1,1,0}; int rm [] = {18724,2304,36,2304,18724}; int gm [] = {9362,1152,18,1152,9362};  

Y usando otros como "rc2" que nunca ha definido.

Su código no se compilará ni funcionará hasta que lo haga autoconsistente.

Tenga en cuenta que user2973 ha encontrado algunos problemas adicionales en su código más allá de los mensajes de error que publicó.


Esta pregunta y respuesta fue traducida automáticamente del idioma inglés.El contenido original está disponible en stackexchange, a quien agradecemos la licencia cc by-sa 3.0 bajo la que se distribuye.
Loading...