Re: Same code problem



Hello everyone,

Can someone confirm to me that there officially is a compiler issue here. I
finaly got the function pointer code to compile in my compiler.... I did some
changes that can probably identify that there is an offcial problem with the
PIC compiler I am using. (Nothing new for everyone in this community I
guess:-) ) I will let you guys decide based on the following discrepencies.

Okay here is the full compilable code for the PIC compiler:
=================================krn.h
typedef long *LRESULT;
typedef long WPARAM;
typedef long LPARAM;

typedef struct tagWnd *pWND;

typedef struct tagHwnd
{ pWND handle;
} HWND;

typedef LRESULT (*WNDPROC)(HWND, long, WPARAM, LPARAM);

typedef struct tagWnd{
WNDPROC lpfnWndProc;
int style;
long backGround;
long titleMsg;
long extra;
} WND;

typedef struct tagRwp{
HWND hwnd;
int showWinEnable;
} RWP;

typedef struct tagMsg{
HWND hwnd;
long msg;
WPARAM wParam;
LPARAM lParam;
long time;
} KM_MSG, *pKM_MSG;

RWP rwp[3] = {0,0,0,0,0,0};
void ULC_KERNEL_dispatch_message(KM_MSG *K);

=====================================krn.c
#include <stdlio.h> // CCS LIBRARY STANDARD LIBRARY
#include <KERNEL.h> // KERNEL HEADER FILE!

LRESULT KWP(HWND x, long m, WPARAM w, LPARAM l);

LRESULT callerFunction(WNDPROC vWNDPROC, HWND h, long m, WPARAM w, LPARAM l);

void main()
{
KM_MSG u; // Create an KM_MSG object
pKM_MSG msg = &u; // Assign the address of a KM_MSG
WND wnd; // Create a WND object

// DEFINE A WINDOW!
wnd.lpfnWndProc = KWP; // Assign a function
wnd.style = 0; // Assign other stuff...

(rwp[0].hwnd).handle = &wnd; // Assign the address of a wnd object
msg->hwnd = rwp[0].hwnd; // Assign a hwnd to another hwnd
ULC_KERNEL_dispatch_message(msg); // Pass a pointer to a msg object
}

void ULC_KERNEL_dispatch_message(KM_MSG *msg)
{
LRESULT zzz;
HWND h;
WND * pwnd;
WNDPROC x;

h = msg->hwnd;
pwnd = h.handle;
x = pwnd->lpfnWndProc;
zzz = callerFunction(x, msg->hwnd, msg->msg, msg->wParam, msg->lParam);
}

LRESULT callerFunction(WNDPROC vWNDPROC, HWND h, long m, WPARAM w, LPARAM l)
{ return (*vWNDPROC) (h, m, w, l);
}

LRESULT KWP(HWND x, long m, WPARAM w, LPARAM l)
{//... other code ...
return 0;
}
============================================

The above compiles without errors or warnings!

However, if I do the following variations for the
ULC_KERNEL_dispatch_message() function, the program does not compile and
shows the error at the callerFunction line:

Variation#1
===========================================
void ULC_KERNEL_dispatch_message(KM_MSG *msg)
{
LRESULT zzz;

zzz = callerFunction(((msg->hwnd).handle)->lpfnWndProc, msg->hwnd, msg->msg,
msg->wParam, msg->lParam);
}

Variation#2
===========================================
void ULC_KERNEL_dispatch_message(KM_MSG *msg)
{
LRESULT zzz;

HWND h;
WND * pwnd;

h = msg->hwnd;
pwnd = h.handle;

zzz = callerFunction(pwnd->lpfnWndProc, msg->hwnd, msg->msg, msg->wParam,
msg->lParam);
}
=======================================

Why would I get errors when I try to dereference the function's name by
doing:
((msg->hwnd).handle)->lpfnWndProc

or doing:

(pwnd->lpfnWndProc)

and why would it compile without errors when I try to derefrence the
function's name by doing it the way with the x?

zzz = callerFunction(x, msg->hwnd, msg->msg, msg->wParam, msg->lParam);

Is this normal behaviour???????

Any comment is appreciated!

--
Best regards
Roberto


"Ben Voigt [C++ MVP]" wrote:

You are right in that you can not use "void *handle" to point to a
function. You can forward declare pointers in a typedef, like this:

typedef node * pnode;

struct node {
pnode next;
int a,b,c;
};
=============================================

Now, I don't know how to make the link between what they are
suggesting and the typedefs that I have at the top of my header... ?

Here is what I tried:

typedef HWND * vHWND;

typedef struct tagHwnd{
//void *handle;
vHWND handle;
} HWND;

Notice the difference between his example, where you are forward using the
struct by its tag name, and your example, where you are forward using the
struct by its typedef name.

Try:

typedef struct tagWnd* pWND;

typedef struct tagHwnd { pWND handle; } HWND;
typedef struct tagWnd { ...... } WND;



.



Relevant Pages

  • Re: Same code problem
    ... some weirdness about pointers as well ... Yup its since early December that I am still trying to complete this snippit of code because I am trying to accomodate my *special* compiler. ... typedef long WPARAM; ... void *handle;} HWND; ...
    (microsoft.public.vc.language)
  • Re: assigning values to a struct
    ... > typedef struct SomeStruct_t ... > help to know that I'm using a keil 8051 C compiler, ... It is your useless 'typedef' that is the problem: ... have remove the useless keyword 'typedef', ...
    (comp.lang.c)
  • Problem with VC++ compiler
    ... I am having a problem with the Visual C++ compiler with the following ... This refers to a typedef that I have written in the code. ...
    (comp.lang.c)
  • Same code problem
    ... compile in VC++ might not compile exactly the same way in the pic compiler. ... typedef long WPARAM; ... typedef long LPARAM; ... HWND hwnd; ...
    (microsoft.public.vc.language)
  • Re: Process dump facility public API - pdpublic.h
    ... typedef struct _DDPREQUEST { ... } DDPREQUEST; ... typedef DDPREQUEST *PDDREQUEST; ... /* Defines for DDPREQUEST flags (flags field within DDPREQUEST structure ...
    (comp.os.os2.bugs)

Loading