This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Advanced C question

I have two questions, I would like to ask:

1) at the moment im refactoring my code and i have 6 functions, which share one function in common, exp.:

< pre>
CodeSelect all;

static void bar(INT32 x)
{ }

void foo1()
{ bar(1);
}

void foo2()
{ bar(2);
}

now my question, is there a trick, i could put foo1 and foo2 in seperate .c files and keep bar still "static" thus invisible to outside linking?

Parents
  • bar.h:

    #ifndef BAR_H
    #define BAR_H
    
    typedef long INT32;
    typedef void (*fp_t)(INT32);
    
    extern fp_t bar;
    
    #endif
    


    bar.c:

    #include "bar.h"
    
    extern void foo1(void), foo2(void);
    
    static void bar_(INT32);
    fp_t bar = bar_;
    
    int main(void)
    {
        foo1();
        foo2();
    
        return 0;
    }
    
    static void bar_(INT32 i)
    {
        (void)i;
    }
    


    foo1.c:

    #include "bar.h"
    
    
    void foo1(void) { bar(1); }


    foo2.c:

    #include "bar.h"
    
    void foo2(void)
    {
        bar(2);
    }
    

Reply
  • bar.h:

    #ifndef BAR_H
    #define BAR_H
    
    typedef long INT32;
    typedef void (*fp_t)(INT32);
    
    extern fp_t bar;
    
    #endif
    


    bar.c:

    #include "bar.h"
    
    extern void foo1(void), foo2(void);
    
    static void bar_(INT32);
    fp_t bar = bar_;
    
    int main(void)
    {
        foo1();
        foo2();
    
        return 0;
    }
    
    static void bar_(INT32 i)
    {
        (void)i;
    }
    


    foo1.c:

    #include "bar.h"
    
    
    void foo1(void) { bar(1); }


    foo2.c:

    #include "bar.h"
    
    void foo2(void)
    {
        bar(2);
    }
    

Children