problem about static Lib and function pointer

This is a discussion on problem about static Lib and function pointer within the C Programming forums, part of the General Programming Boards category; Hi,all My problem is : in my project i am using several files and a static library , totally written ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    16

    problem about static Lib and function pointer

    Hi,all

    My problem is :

    in my project i am using several files and a static library , totally written in ansi c.

    1,file a.c is a file do the upper side operation, it will call some functions in b.lib, there is a strut like this in a.c.

    typedef struct {
    unsigned char *name;
    int (*function1)(void *p);
    int (*function2)(xxxxx);

    } strA;

    in the init time of upper operation, the function pointer will be set . They will link to the real function in the b.lib.
    (say,like the following)
    strA sp;
    sp.function1 = &functionAInFile1;


    2, in b.lib, there are several c files every of which does the same job but in different ways. (say , they are File1.c; File2.c; File3.c ...)
    in every c file, there are some functions that for the function pointers to link to.

    When I debug, the a.c can successfully call the function in the File1.c or others. but, when it runs into the real function, I find the system can not recognize the local struct in the File1.c or others c files.

    just like that
    /* 1.c details */
    #including <stdio.h>
    ...

    typedef struct {
    xxxxx
    xxxxx
    } structLocalInFile1;

    /* one function */
    int functionAInFile1(void *p)
    {
    StructLocalIn1 *localP = (StructLocalIn1 *)p;
    .....

    return 0;
    }

    /* another function */
    int functionBInFile1() {
    int a;

    ...

    return 0;

    }

    in the immediate window of VC6, when it runs into the functionAInFile1,
    I find the compiler can not recognize the StructLocalIn1 struct.

    I don't know why.

    Any commend is welcome.

    Thanks in advance.

    Wu7up

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078

    Re: problem about static Lib and function pointer

    Originally posted by wu7up
    in the immediate window of VC6, when it runs into the functionAInFile1,
    I find the compiler can not recognize the StructLocalIn1 struct.

    I don't know why.

    Any commend is welcome.

    Thanks in advance.

    Wu7up
    Because it's

    structLocalInFile1

    not

    StructLocalInFile1



    EDIT: also, make sure that you include a forward declaration of the struct. If you want the definition in another module, then this means that you'll have to give your struct a name in the header (IE you won't be able to just typedef it).
    Last edited by Polymorphic OOP; 02-24-2003 at 08:16 AM.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    16

    Re: Re: problem about static Lib and function pointer

    Originally posted by Polymorphic OOP
    Because it's

    structLocalInFile1

    not

    StructLocalInFile1



    EDIT: also, make sure that you include a forward declaration of the struct. If you want the definition in another module, then this means that you'll have to give your struct a name in the header (IE you won't be able to just typedef it).
    --------------------------------------------------------------------------------

    Sorry, I made a mistyping when I post this message.
    It is ok in my program.

    I think maybe it is the forward declaration problem.I will try tomorrow morning.

    By the way, where do you think I can do the forward declaration ?
    in the File a.c ?

    Thank you.

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Nono, you have to put the forward declaration in a file that 1.c includes. If you don't do that then it would be oblivious to the datatype. You can't put a declaration in a completely different cpp and expect all others to be able to access it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem in mouse position
    By Arangol in forum Game Programming
    Replies: 6
    Last Post: 08-08-2006, 07:07 AM
  2. Compiled GLOW into static lib
    By cboard_member in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 03-05-2006, 02:01 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. help me using lib from Visual C++ 6
    By oskilian in forum Windows Programming
    Replies: 3
    Last Post: 10-11-2001, 11:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21