Skip to content

Instantly share code, notes, and snippets.

@ramntry
Created December 10, 2014 13:17
Show Gist options
  • Select an option

  • Save ramntry/e37fa85edbd633c1749f to your computer and use it in GitHub Desktop.

Select an option

Save ramntry/e37fa85edbd633c1749f to your computer and use it in GitHub Desktop.
#include <stdio.h>
char buf[32] = "Hello World";
char *bufptr = buf;
void f(char **x) {
printf("%s\n", *x);
}
int main() {
f(&bufptr); // OK; OK
f(&buf); // Warning; Segmentation Fault
return 0;
}
@ramntry
Copy link
Author

ramntry commented Dec 10, 2014

main.c: In function ‘main’:
main.c:12:3: warning: passing argument 1 of ‘f’ from incompatible pointer type [enabled by default]
   f(&buf);     // Warning; Segmentation Fault
   ^
main.c:6:6: note: expected ‘char **’ but argument is of type ‘char (*)[32]’
 void f(char **x) {
      ^
ramntry@roman-tereshin-GS60:~/tmp/carray$ ./a.out 
Hello World
Segmentation fault (core dumped)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment