C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Function with pointer parameter Posted by kikijas on 26 Mar 2007 at 1:35 AM
This message was edited by kikijas at 2007-3-26 1:40:11

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.


Report
Re: Function with pointer parameter Posted by bilderbikkel on 26 Mar 2007 at 1:45 AM
: int Funct1(UL32 * para1, UL32 para2);
: typedef unsigned long UL32;
:
: void main() //main is of return type int
: {
: STRUCTDEF2 val;
: unsigned long val2;
:
: if(Funct1((UL32*)&val, val2)) //val is of type STRUCTDEF2
//so this a 'dirty' cast


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

Good luck and appreciate the type safety,
bilderbikkel

Report
Re: Function with pointer parameter Posted by kikijas on 26 Mar 2007 at 2:27 AM
This message was edited by kikijas at 2007-3-26 2:32:56

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!!!



Report
Re: Function with pointer parameter Posted by bilderbikkel on 26 Mar 2007 at 2:49 AM
: This message was edited by kikijas at 2007-3-26 2:32:56

: 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:

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


Hoped to have helped you out,

bilderbikkel




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.