Hi, I have a problem with c files.
I have broken my code to 2 files main.c and unp.h

unp.h

typedef void (*Ptr_To_Function)(void);

struct Menu_Record
{
    unsigned int option_number;
    const char * text;
    Ptr_To_Function process_function;
};

struct Menu_Record* select(struct Menu_Record*,int);

struct Menu_Record startup[] =
{
    {1, "Choice1", NULL},
    {2, "Choice2",NULL},
    {0, "Exit", NULL}
};

main.c

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

#include "unp.h" 


int main()
{
return 0;
}

struct Menu_Record* select(struct Menu_Record* menu, int num_options)
{
}

But when I compile I take errors

In file included from main.c:6:
unp.h:10: error: conflicting types for Α select Α
/usr/include/sys/select.h:109: note: previous declaration of Α select Α was he
re
client.c:57: error: conflicting types for Α select Α
/usr/include/sys/select.h:109: note: previous declaration of Α select Α was he
re

Edited 5 Years Ago by peter20: n/a

Never declare data objects in a header file because if you include the same header file in multiple *.c or *.cpp files the compiler will generate multiple declaration errors. So you want to move lines 12 - 17 of that header file into the *.c file (about line 7).

The key piece of information is the location of select(): "/usr/include/sys/select.h". This is the POSIX version, which means it's being linked automatically and you need to rename your select() function to avoid conflicting with it.

This article has been dead for over six months. Start a new discussion instead.