How to resolve “conflicting types error” in C?

后端 未结 7 625
情话喂你
情话喂你 2021-01-27 16:33

For the following C code (for swapping two numbers) I am getting the \"conflicting types\" error for swap function:

#include 
#includ         


        
7条回答
  •  温柔的废话
    2021-01-27 17:01

    Well, it compiles on http://codepad.org (after removing the getch(), which is irrelevant). Maybe your compiler complains about using memcpy on non-restricted pointers?

    In swap() p1 and p2 are not guaranteed not to be aliases. This is an actual bug waiting to happen - calling swap on &a[i] and &a[j] might blow up memcpy when i==j. Either use memmove (which is guaranteed not to blow up on overlapped areas) or declare the pointers restricted.

提交回复
热议问题