projectNe10 / Ne10

An open optimized software library project for the ARM® Architecture
Other
1.46k stars 408 forks source link

dereferencing -Wpointer-arith #50

Closed ghost closed 11 years ago

ghost commented 11 years ago

@Hello,

dereferencing and pointer-arithmetic on void pointers is not permitted by the standard since sizeof(void) is undefined, moreover, Wimplicit-function-declaration, please declare your function prototypes or use extern, that's easy.

yangzhang commented 11 years ago

Hi I'm not very clear what you mean? could you give me an example?

ghost commented 11 years ago

@hello,

add this flag to your build script -Wpointer-arith

(flag which matters to many folks, especially when dealing with SIMD types and in a greater concern memory alignments and generic pointer arithmetics)

example

/** gcc test.c -Wall -Wpointer-arith **/
#include <stdio.h>

int main (int argc, char **argv)
{
  void * bar;
  void * foo;
  foo = bar + 1;
  return 0;
}
/**
test.c: In function ‘main’:
test.c:8: warning: pointer of type ‘void *’ used in arithmetic
**/

Wimplicit-function-declaration warning is triggered when there is a lack of function prototype declaration, K&R is dead.

example

/** gcc test.c -Wall **/
int main (int argc, char **argv)
{
    const char * bar = "hello";
    long l = strlen(bar);
    void * foo;
    foo = bar + 1;
    return 0;
}
/**
test.c: In function ‘main’:
test.c:4: warning: implicit declaration of function ‘strlen’
test.c:4: warning: incompatible implicit declaration of built-in function ‘strlen’
test.c:6: warning: assignment discards qualifiers from pointer target type
test.c:4: warning: unused variable ‘l’
**/

let me know,

Cheers!

yangzhang commented 11 years ago

thanks, I will try it!

ghost commented 11 years ago

ignorance is made of attempts, knowledge is made of acts.

Cheers.