Article View: comp.os.os2.programmer
Article #1166Re: C Set/2
From: dave
Date: Thu, 20 Aug 1992 17:43
Date: Thu, 20 Aug 1992 17:43
66 lines
2774 bytes
2774 bytes
In <1992Aug19.203811.15056@natinst.com> Uma Arunkumar writes:
> (restructured a bit -- dmm)
>
> struct {
> short a;
> short b;
> short (* fun_name)();
> } command;
>
> extern short Test1(short p, short q, short r);
> extern short Test2(short x, short y);
>
> commands cmd_array[] = {
> {1, 2, Test1}
> {3, 4, Test2}
> };
>
> icc /c /w3 /o+ prog1.c prog1a.h prog1b.h
>
> 1. error EDC0227 : The return types of the functionm pointers are incompatible.
> 2. informational EDC0140: Operand has type pointer to _Optlink function returning signed short integer.
> 3. informational EDC0140: Operand has type _Optlink function returning signed short integer.
First of all, the error message is lying to you. It's not the return
types of the function pointers which are incompatible -- it's the
parameter lists. Your example can be chopped down to:
int f(short);
int (*fp)();
fp = f;
For two function pointers to be compatible, their parameters lists must
be compatible. If one of the parameter lists is empty and one isn't, all
the parameters in the non-empty list must be wide types (ie, not char,
short, or float). All the gory details are in section 3.5.4.3 of the
ANSI C Standard, but the upshot is that a function with a short parameter
is not compatible with a function pointer with no parameters.
We are easing up on this restriction in our next release (for the benefit
of people like you, whose code suddenly stops working), but in the mean
time, you can get around this problem by sticking in explicit casts on
the assignments:
typedef short (* fptype)();
typedef struct {
short a;
short b;
fptype fun_name;
} command;
extern short Test1(short p, short q, short r);
extern short Test2(short x, short y);
command cmd_array[] = {
{1, 2, (fptype)Test1},
{3, 4, (fptype)Test2}
};
dave
-------------------------------------------------------------------------
Dave Mooney dmm@vnet.ibm.com
C Set/2 Development, IBM Canada Lab, 844 Don Mills Rd, Toronto, Ontario
"If you've got a blacklist, I want to be on it"
Technical Details
Message-ID:
<19920820.121934.870@almaden.ibm.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!vnet.ibm.comReferences:
<1992Aug19.203811.15056@natinst.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!vnet.ibm.com From: dmm@vnet.ibm.com (dave) Message-ID: <19920820.121934.870@almaden.ibm.com> Date: Thu, 20 Aug 92 13:43:25 EDT Newsgroups: comp.os.os2.programmer,comp.os.os2.misc Subject: Re: C Set/2 Organization: IBM Canada Lab News-Software: UReply 3.0 X-X-From: dmm@vnet.ibm.com (Dave Mooney) References: <1992Aug19.203811.15056@natinst.com> Lines: 66