fork download
  1. //given 2 distinct types
  2. struct Foo{ int a,b,c; };
  3. struct Bar{ float x,y,z; };
  4.  
  5. //and a function that takes each type by pointer
  6. void function(struct Foo* x, struct Bar* y){}
  7.  
  8. int main() {
  9. struct Foo x;
  10. struct Bar y;
  11.  
  12. //why am I able to pass both parameters in the wrong order,
  13. //and still get a successful compile without any warning messages.
  14. function(&y,&x);
  15.  
  16. //compiles without warnings.
  17. //potentially segfaults based on the implementation of the function
  18. }
  19. deliberate error here
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'main':
prog.c:14:11: warning: passing argument 1 of 'function' from incompatible pointer type [-Wincompatible-pointer-types]
  function(&y,&x);
           ^
prog.c:6:6: note: expected 'struct Foo *' but argument is of type 'struct Bar *'
 void function(struct Foo* x, struct Bar* y){}
      ^
prog.c:14:14: warning: passing argument 2 of 'function' from incompatible pointer type [-Wincompatible-pointer-types]
  function(&y,&x);
              ^
prog.c:6:6: note: expected 'struct Bar *' but argument is of type 'struct Foo *'
 void function(struct Foo* x, struct Bar* y){}
      ^
prog.c: At top level:
prog.c:19:1: error: unknown type name 'deliberate'
 deliberate error here
 ^
prog.c:19:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'here'
 deliberate error here
                  ^
stdout
Standard output is empty