Wie zu beheben "conflicting types Fehler" in C?

Für die folgenden C-code (für das austauschen von zwei zahlen) bin ich immer die "Konflikt-Typen" Fehler für swap Funktion:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b;
    printf("enter the numbers to be swapped");
    scanf("%d%d",&a,&b);
    printf("before swap");
    printf("a=%d,b=%d",a,b);
    swap(&a,&b,sizeof(int));
    printf("after swap");
    printf("a=%d,b=%d",a,b);
    getch();   
}
void swap(void *p1,void *p2,int size)
{
     char buffer[size];
     memcpy(buffer,p1,size);
     memcpy(p1,p2,size);
     memcpy(p2,buffer,size);
     return(0);
}

Compiler Diagnose:

<source>:10:6: warning: implicit declaration of function 'swap' [-Wimplicit-function-declaration]
  swap(&a,&b,sizeof(int));

  ^~~~
program:15:6: warning: conflicting types for 'swap'
 void swap(void *p1,void *p2,int size)
     ^~~~

Kann jemand sagen warum dieser Fehler kommt?

Was ist die Lösung dafür?

InformationsquelleAutor Madhan | 2009-11-22
Schreibe einen Kommentar