sharing a function between 2 .c files

前端 未结 3 1112
无人共我
无人共我 2021-01-29 10:24

dir1 has dir2, file1.c and file1.h.

dir2 has file2.c

Now, if I want to access a function defined in file1.c in file2.c, I need to declare it in file1.h and inclu

3条回答
  •  执念已碎
    2021-01-29 11:10

    Now, if I want to access a function defined (in) file1.c in file2.c

    A function defined in FILE1.c Access from FILE2.c example function: void sync(all){start sync ...}

    Need on File2.h

    include File1.h

    AND Need on File2.c

    include File1.h

    Nothing else!

    I always use also the keyword EXTERN in File2.h

    Example:

    extern void sync(all);

    The voted also work, choose with what you feel better, I feel better when I saw what happend during coding. Imagine an other team member has to review your code, it will be harder...

提交回复
热议问题