Robby
2009-12-26 17:56:01 UTC
Hello,
This is interesting.... to me anyways.
#1) We know that we are allowed to *declare* a function prototype in a
header like this:
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam);
#2) We know we are allowed to include a header file in several .c files.
Having said this, there is an inconsistency that stands out here. Probably
my fault again, but nontheless, I am stumped.
Please carefully view the small program sample:
=========================KERNEL.h
typedef long *LRESULT;
typedef long WPARAM;
typedef long LPARAM;
typedef struct tagHwnd {
long caption_msg;
} HWND;
typedef struct tagMsg {
HWND hwnd;
long msg;
WPARAM wParam;
LPARAM lParam;
long time;
} KM_MSG;
typedef LRESULT(*callBack)(HWND hwnd, long message, WPARAM w, LPARAM l);
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam);
=========================KERNEL.c
#include <stdio.h>
#include "KERNEL.h"
callBack cb[1];
int main(void)
{
KM_MSG m; HWND hwnd;
hwnd.caption_msg = 1; m.msg = 1; m.lParam = 2; m.wParam = 3;
cb[0] = CALLBACK_WP_INTRO;
CALLBACK_WP_INTRO(hwnd, m.msg, m.wParam, m.lParam);
}
=========================WP_INTRO.h
// no code!
=========================WP_INTRO.c
#include "KERNEL.h"
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam)
{
return 0;
}
==================================
As you can very well see, the following function prototype:
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam);
is included twice. The first time by KERNEL.c and the second time by the
WP_INTRO.c from the following inclusion command:
#include "KERNEL.h"
Now, this compiles... no errors and no warnings.
//////////////////////////////////////////////////////////////
But now consider the following small program sample where the same prototype
function is still included twice.... still using the #include pre-proccesor
directives. however this time it generating errors ????
=========================KERNEL.h
typedef long *LRESULT;
typedef long WPARAM;
typedef long LPARAM;
typedef struct tagHwnd {
long caption_msg;
} HWND;
typedef struct tagMsg {
HWND hwnd;
long msg;
WPARAM wParam;
LPARAM lParam;
long time;
} KM_MSG;
typedef LRESULT(*callBack)(HWND hwnd, long message, WPARAM w, LPARAM l);
=========================KERNEL.c
#include <stdio.h>
#include "KERNEL.h"
#include "WP_INTRO.h"
callBack cb[1];
int main(void)
{
KM_MSG m; HWND hwnd;
hwnd.caption_msg = 1; m.msg = 1; m.lParam = 2; m.wParam = 3;
cb[0] = CALLBACK_WP_INTRO;
CALLBACK_WP_INTRO(hwnd, m.msg, m.wParam, m.lParam);
}
=========================WP_INTRO.h
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam);
=========================WP_INTRO.c
#include "WP_INTRO.h"
#include "KERNEL.h"
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam)
{
return 0;
}
====================================
Again, as you can very well see, the following function prototype:
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam);
is also included twice. The first time by KERNEL.c with the following
inclusion:
#include "WP_INTRO.h"
and the second time by the WP_INTRO.c from the following inclusion command:
#include "WP_INTRO.h"
But this time I get the following errors:
1>c:\_dts_programming\pic\_microchip_issues\vc++\function_pointers\function_pointers\wp_intro.h(1)
: error C2061: syntax error : identifier 'CALLBACK_WP_INTRO'
1>c:\_dts_programming\pic\_microchip_issues\vc++\function_pointers\function_pointers\wp_intro.h(1) : error C2059: syntax error : ';'
1>c:\_dts_programming\pic\_microchip_issues\vc++\function_pointers\function_pointers\wp_intro.h(1)
: error C2146: syntax error : missing ')' before identifier 'hwnd'
1>c:\_dts_programming\pic\_microchip_issues\vc++\function_pointers\function_pointers\wp_intro.h(1) : error C2061: syntax error : identifier 'hwnd'
1>c:\_dts_programming\pic\_microchip_issues\vc++\function_pointers\function_pointers\wp_intro.h(1) : error C2059: syntax error : ','
1>c:\_dts_programming\pic\_microchip_issues\vc++\function_pointers\function_pointers\wp_intro.h(1) : error C2059: syntax error : ')'
The reason why I am trying to code it this way, is that I was trying to
include the function prototype in the correct header which belongs to the
respective .c file.
For example, *I think* all function prototypes should be declared in the
specific header which is included by a .c file which carries the function's
definitions.
All help appreciated!
This is interesting.... to me anyways.
#1) We know that we are allowed to *declare* a function prototype in a
header like this:
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam);
#2) We know we are allowed to include a header file in several .c files.
Having said this, there is an inconsistency that stands out here. Probably
my fault again, but nontheless, I am stumped.
Please carefully view the small program sample:
=========================KERNEL.h
typedef long *LRESULT;
typedef long WPARAM;
typedef long LPARAM;
typedef struct tagHwnd {
long caption_msg;
} HWND;
typedef struct tagMsg {
HWND hwnd;
long msg;
WPARAM wParam;
LPARAM lParam;
long time;
} KM_MSG;
typedef LRESULT(*callBack)(HWND hwnd, long message, WPARAM w, LPARAM l);
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam);
=========================KERNEL.c
#include <stdio.h>
#include "KERNEL.h"
callBack cb[1];
int main(void)
{
KM_MSG m; HWND hwnd;
hwnd.caption_msg = 1; m.msg = 1; m.lParam = 2; m.wParam = 3;
cb[0] = CALLBACK_WP_INTRO;
CALLBACK_WP_INTRO(hwnd, m.msg, m.wParam, m.lParam);
}
=========================WP_INTRO.h
// no code!
=========================WP_INTRO.c
#include "KERNEL.h"
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam)
{
return 0;
}
==================================
As you can very well see, the following function prototype:
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam);
is included twice. The first time by KERNEL.c and the second time by the
WP_INTRO.c from the following inclusion command:
#include "KERNEL.h"
Now, this compiles... no errors and no warnings.
//////////////////////////////////////////////////////////////
But now consider the following small program sample where the same prototype
function is still included twice.... still using the #include pre-proccesor
directives. however this time it generating errors ????
=========================KERNEL.h
typedef long *LRESULT;
typedef long WPARAM;
typedef long LPARAM;
typedef struct tagHwnd {
long caption_msg;
} HWND;
typedef struct tagMsg {
HWND hwnd;
long msg;
WPARAM wParam;
LPARAM lParam;
long time;
} KM_MSG;
typedef LRESULT(*callBack)(HWND hwnd, long message, WPARAM w, LPARAM l);
=========================KERNEL.c
#include <stdio.h>
#include "KERNEL.h"
#include "WP_INTRO.h"
callBack cb[1];
int main(void)
{
KM_MSG m; HWND hwnd;
hwnd.caption_msg = 1; m.msg = 1; m.lParam = 2; m.wParam = 3;
cb[0] = CALLBACK_WP_INTRO;
CALLBACK_WP_INTRO(hwnd, m.msg, m.wParam, m.lParam);
}
=========================WP_INTRO.h
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam);
=========================WP_INTRO.c
#include "WP_INTRO.h"
#include "KERNEL.h"
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam)
{
return 0;
}
====================================
Again, as you can very well see, the following function prototype:
LRESULT CALLBACK_WP_INTRO(HWND hwnd, long message, WPARAM wParam, LPARAM
lParam);
is also included twice. The first time by KERNEL.c with the following
inclusion:
#include "WP_INTRO.h"
and the second time by the WP_INTRO.c from the following inclusion command:
#include "WP_INTRO.h"
But this time I get the following errors:
1>c:\_dts_programming\pic\_microchip_issues\vc++\function_pointers\function_pointers\wp_intro.h(1)
: error C2061: syntax error : identifier 'CALLBACK_WP_INTRO'
1>c:\_dts_programming\pic\_microchip_issues\vc++\function_pointers\function_pointers\wp_intro.h(1) : error C2059: syntax error : ';'
1>c:\_dts_programming\pic\_microchip_issues\vc++\function_pointers\function_pointers\wp_intro.h(1)
: error C2146: syntax error : missing ')' before identifier 'hwnd'
1>c:\_dts_programming\pic\_microchip_issues\vc++\function_pointers\function_pointers\wp_intro.h(1) : error C2061: syntax error : identifier 'hwnd'
1>c:\_dts_programming\pic\_microchip_issues\vc++\function_pointers\function_pointers\wp_intro.h(1) : error C2059: syntax error : ','
1>c:\_dts_programming\pic\_microchip_issues\vc++\function_pointers\function_pointers\wp_intro.h(1) : error C2059: syntax error : ')'
The reason why I am trying to code it this way, is that I was trying to
include the function prototype in the correct header which belongs to the
respective .c file.
For example, *I think* all function prototypes should be declared in the
specific header which is included by a .c file which carries the function's
definitions.
All help appreciated!
--
Best regards
Roberto
Best regards
Roberto