Advertisement
obernardovieira

[Solution] -Wsizeof-pointer-memaccess warning

Jun 28th, 2014
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.30 KB | None | 0 0
  1. //not by me
  2. //https://gcc.gnu.org/gcc-4.8/porting_to.html
  3.  
  4. #include <string.h>
  5.  
  6. struct A { };
  7.  
  8. int main(void)
  9. {
  10.     A obj;
  11.     A* p1 = &obj;
  12.     A p2[10];
  13.  
  14.     memset(p1, 0, sizeof(p1)); // error
  15.     memset(p1, 0, sizeof(*p1)); // ok, dereferenced
  16.     memset(p2, 0, sizeof(p2)); // ok, array
  17.  
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement