I need help with passing pointers in function calls

This is a discussion on I need help with passing pointers in function calls within the C Programming forums, part of the General Programming Boards category; Hi all, pretty glad to find this page. i am a newbie and need your help please!!! This is somehow ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    5

    I need help with passing pointers in function calls

    Hi all,

    pretty glad to find this page. i am a newbie and need your help please!!!

    This is somehow related to information hiding.

    function A is high level, function B is in between, and function C is a library function, which is a low-level driver. I need function A to call function B, then function B passes all parameters it receives from function A to function C. So function B hides function C from function A.

    The low-level driver library function C requires 4 parameters
    a) address of the structure
    b) address of the stack array
    c) address of the message buffer
    d) length of the message buffer

    and it has the following prototype
    void functionC(structC *tcb, unsigned int *stack, unsigned char *mes_buf, unsigned int mes_length);

    Now I need to write my function B to act as a middle-man between function A and function C, so that the high-level function A doesn't need to know anything about function C. All function B needs to do is to pass all parameters from A to to C.

    I tried the following prototype for function B
    void functionB(structC *tcb, unsigned int *stack, unsigned char *mes_buf, unsigned int mes_length);
    then use function A to call it with
    functionB(&tcb, &stack[top_stack-1], &mes_buf, mes_length);
    but it did pass all parameters to function C correctly.
    Then I tried this prototype for function B
    void functionB(structC tcb, unsigned int stack, unsigned char mes_buf, unsigned int mes_length);
    then use function A to call it with
    functionB(tcb, stack[top_stack-1], mes_buf[0], mes_length);
    but it still did not work.

    Both implementations got compiled and linked successfully though, and none worked.

    There must be something wrong with my code, and there must be at least one way to do it, but I don't know. Please, help. I don't know what to do now.

    Thanks in advance,

    Vien.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    5
    Sorry,
    In my original post, I had some typo errors in there.

    Correction is as follow:

    In both case, function B did NOT pass all parameters from A to C correctly.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You're on the right track:

    void funA( int *x ) { funB( x ); }
    void funB( int *y ) { funC( y ); }
    void funC( int *z ) { printf("%d\n", (*z) ); }

    You just use the argument names that funB gets as the arguments to te call for funC.

    Call funA...

    int x = 10;
    funA( &x );


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    5
    Thank you so much Quzah. I'll get on to that right away. Hope it will solve this problem for me.

    Again, I apprciate your help, as well as the wonderful board.

    Vien Nguyen.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing A Function From One Object to Another
    By HalNineThousand in forum C++ Programming
    Replies: 8
    Last Post: 03-28-2008, 07:26 PM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  3. Replies: 4
    Last Post: 11-23-2003, 06:15 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM

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