ni/src/SDL/debugger.cpp:1283:13: error: 'int i' previously declared here eclipse

-1

okay so I'm currently working on an android application in eclipse using the android sdk and adt etc. while I'm compiling my code I'm getting errors I've racked my brain for days looked up similar threads on here before posting but none suited my satisfaction as I tried the various solutions similar to my problem.

being used in eclipse for compiling:

Toolchain: android GCC

Builder: android builder

GNU C++

here are the errors I'm getting:

jni/src/SDL/debugger.cpp:436:21: error: format not a string literal and no format arguments [-Werror=format-security]
       printf(m->name);
                     ^
jni/src/SDL/debugger.cpp: In function 'void debuggerMemoryByte(int, char**)':
jni/src/SDL/debugger.cpp:1292:11: error: redeclaration of 'int i'
       int i = debuggerReadByte(addr+8);
           ^
jni/src/SDL/debugger.cpp:1283:13: error: 'int i' previously declared here
     for(int i = 0; i < 16; i++) {
             ^
jni/src/SDL/debugger.cpp: In function 'void debuggerMemoryHalfWord(int, char**)':
jni/src/SDL/debugger.cpp:1328:11: error: redeclaration of 'int i'
       int i = debuggerReadByte(addr+8);
           ^
jni/src/SDL/debugger.cpp:1319:13: error: 'int i' previously declared here
     for(int i = 0; i < 16; i++) {
             ^
jni/src/SDL/debugger.cpp: In function 'void debuggerMemory(int, char**)':
jni/src/SDL/debugger.cpp:1366:11: error: redeclaration of 'int i'
       int i = debuggerReadByte(addr+8);
           ^
jni/src/SDL/debugger.cpp:1355:13: error: 'int i' previously declared here
     for(int i = 0; i < 16; i++) {
             ^
jni/src/SDL/debugger.cpp: In function 'void debuggerOutput(char*, u32)':
jni/src/SDL/debugger.cpp:1403:13: error: format not a string literal and no format arguments [-Werror=format-security]
     printf(s);
             ^
cc1plus.exe: some warnings being treated as errors
make.exe: *** [obj/local/armeabi/objs/main/SDL/debugger.o] Error 1

here is the some of the code sample:

    for(int i = 0; i < 16; i++) {
      int a = debuggerReadByte(addr);
      int b = debuggerReadByte(addr+1);
      int c = debuggerReadByte(addr+2);
      int d = debuggerReadByte(addr+3);
      int e = debuggerReadByte(addr+4);
      int f = debuggerReadByte(addr+5);
      int g = debuggerReadByte(addr+6);
      int h = debuggerReadByte(addr+7);
      int i = debuggerReadByte(addr+8);
      int j = debuggerReadByte(addr+9);
      int k = debuggerReadByte(addr+10);
      int l = debuggerReadByte(addr+11);
      int m = debuggerReadByte(addr+12);
      int n = debuggerReadByte(addr+13);
      int o = debuggerReadByte(addr+14);
      int p = debuggerReadByte(addr+15);

    printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
             addr,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,
             ASCII(a),ASCII(b),ASCII(c),ASCII(d),
             ASCII(e),ASCII(f),ASCII(g),ASCII(h),
             ASCII(i),ASCII(j),ASCII(k),ASCII(l),
             ASCII(m),ASCII(n),ASCII(o),ASCII(p));
      addr += 16;
    }
  } else
    debuggerUsage("mb");    
}

void debuggerMemoryHalfWord(int n, char **args)
{
  if(n == 2) {
    u32 addr = 0;
    sscanf(args[1], "%x", &addr);
    addr = addr & 0xfffffffe;
    for(int i = 0; i < 16; i++) {
      int a = debuggerReadByte(addr);
      int b = debuggerReadByte(addr+1);
      int c = debuggerReadByte(addr+2);
      int d = debuggerReadByte(addr+3);
      int e = debuggerReadByte(addr+4);
      int f = debuggerReadByte(addr+5);
      int g = debuggerReadByte(addr+6);
      int h = debuggerReadByte(addr+7);
      int i = debuggerReadByte(addr+8);
      int j = debuggerReadByte(addr+9);
      int k = debuggerReadByte(addr+10);
      int l = debuggerReadByte(addr+11);
      int m = debuggerReadByte(addr+12);
      int n = debuggerReadByte(addr+13);
      int o = debuggerReadByte(addr+14);
      int p = debuggerReadByte(addr+15);

also it appears that also getting these errors as well, Function 'sscanf' could not be resolved, and Function 'printf' could not be resolved. which bugs me.

I Have included all the header files etc. but not really sure where to go from there I hope someone here can let me know exactly whats going on with the errors stated above, and thanks for the help.

to me the code looks correct but not sure where it maybe wrong.

android
c++
eclipse
asked on Stack Overflow Jan 4, 2015 by Shadowman • edited Jan 4, 2015 by rici

2 Answers

1

The problem is that you are declaring the variable "int i" twice - Once when creating the loop int i = 0 and once inside it int i = debuggerReadByte(addr+8);. You can solve it by changing the name of one of the variables like for(int z = 0; z < 16; z++).

answered on Stack Overflow Jan 4, 2015 by Sir Codesalot
0
error: redeclaration of 'int i'

You can simply rename the loop control variable to something else, since you do not use it in the loop anyway.

error: format not a string literal and no format arguments [-Werror=format-security]

You can avoid this by using fputs() or puts() (but that appends a new line, IIRC) instead.

also it appears that also getting these errors as well, Function 'sscanf' could not be resolved, and Function 'printf' could not be resolved. which bugs me.

Try including <cstdio> and use std:: prefix. Your code snippet does not show the includes.

answered on Stack Overflow Jan 4, 2015 by wilx

User contributions licensed under CC BY-SA 3.0