Search code examples
cgcccompiler-errorsexpected-exception

expected identifier before the name of the function on first line


I have a code:

void switch (int *a, int *b) 
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

It's the function I include in other .c file by this one .h file:

#ifndef SWITCHINT_H
#define SWITCHINT_H

void switch (int *a, int *b);

#endif

But console prints that:

switchInt.c:1:5: error: expected identifier or ‘(’ before ‘switch’
 void switch (int *a, int *b);s
switchInt.h:4:6: error: expected identifier or ‘(’ before ‘switch’
 void switch (int *a, int *b);

What should i do?


Solution

  • The error occurred due to a reserved name of the function ("switch")

    Thanks Fiddling Bits for help!

    P.S: I'm sorry for being so blind :(