Function with pointer parameter

[b][red]This message was edited by kikijas at 2007-3-26 1:40:11[/red][/b][hr]
I have part of my c-codes as below:

//prototype
int Funct1(UL32 * para1, UL32 para2);

typedef unsigned long UL32;

typedef struct STRUCTDEF1
{
unsigned char Data3;
unsigned int Data2;
}STRUCTDEF1;

typedef struct STRUCTDEF2
{
unsigned int Data1;
STRUCTDEF1 DataBuf1;
}STRUCTDEF2, *P_STRUCTDEF2;

void main()
{
STRUCTDEF2 val;
unsigned long val2;

.
.
.

if(Funct1((UL32*)&val, val2))
{
. . .
}
.
.
.
}

int Funct1(UL32 * para1, UL32 para2)
{
..
..
..
}

I am using the open watcom compiler. I need to build this program into a DOS 32-bit executable program. I am facing the problem below:

When I call the Funct1 by passing the parameter as following:

Funct1(&val1, val2)

The compiler gives the error message "Type of parameter 1 does not agree with previous definition". There are 2 notes saying that "Source conversion type is 'struct _STRUCTDEF2 *'" and "target conversion type is 'unsigned long *'".
So I try to cast the "&val" to UL32 when I call the "Funct1()" in the main function, as shown in my codes above.
This does solved the problem, but will it pass the correct parameters to the function "Funct1"?

How can I display the value of the "para1" in Funct1?

Highly appreciated if anyone can help to answer the above questions.


Comments

  • : int Funct1(UL32 * para1, UL32 para2);
    : typedef unsigned long UL32;
    :
    : void main() [red]//main is of return type int[/red]
    : {
    : STRUCTDEF2 val;
    : unsigned long val2;
    :
    : if(Funct1((UL32*)&val, val2)) [red]//val is of type STRUCTDEF2
    //so this a 'dirty' cast[/red]

    : How can I display the value of the "para1" in Funct1?
    Which value of para1?

    Good luck and appreciate the type safety,
    bilderbikkel

  • [b][red]This message was edited by kikijas at 2007-3-26 2:32:56[/red][/b][hr]
    Hi bilderbikkel,

    I am new to pointer. Hope that you could give some suggestion on how to solve the code problem ( for the cast value).

    I would like to display "Data3" of "para1".

    Thanks alot!!!



  • : [b][red]This message was edited by kikijas at 2007-3-26 2:32:56[/red][/b][hr]
    : Hi bilderbikkel,
    :
    : I am new to pointer. Hope that you could give some suggestion on how to solve the code problem ( for the cast value).
    :
    : I would like to display "Data3" of "para1".
    :

    I guess you want to pass the entire struct to Funct1:

    [code]
    int Funct1(STRUCTDEF1 * para1, UL32 para2)
    {
    //Reading
    unsigned char copy = para1->Data3;
    //Writing
    para1->Data3 = 0.0;
    }
    [/code]

    Hoped to have helped you out,

    bilderbikkel

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories