Re: resolving a warning error

From: Eric Sosman (eric.sosman_at_sun.com)
Date: 10/29/04


Date: Fri, 29 Oct 2004 13:13:01 -0400

Dan Pop wrote:
> In <clrhlg$4vs$1@news1brm.Central.Sun.COM> Eric Sosman <eric.sosman@sun.com> writes:
>
>>Dan Pop wrote:
>>
>>>In <clr2s8$f0s$1@news1brm.Central.Sun.COM> Eric Sosman <eric.sosman@sun.com> writes:
>>>
>>>>michael potter wrote:
>>>>
>>>>>I would like to code a prototype that returns an enum, but not declare
>>>>>the enum.
>>>>>[...]
>>>>>How can I eliminate that warning message without eliminating other
>>>>>warning messages and without declaring the enum?
>>>>
>>>> By using `int someFunc(void);' instead.
>>>
>>>Can I have the chapter and verse stating that enumerated types are
>>>compatible with type int?
>>
>> No, of course not: 6.7.2.2/4 lists the allowable
>>types, and not all are necessarily compatible with `int'
>>on all implementations.
>
> Free clue: the concept of compatible types is NOT implementation
> dependent. It is the C standard itself that specifies what types are
> compatible:
>
> 1 Two types have compatible type if their types are the
> same. Additional rules for determining whether two types are
> compatible are described in 6.7.2 for type specifiers, in 6.7.3
> for type qualifiers, and in 6.7.5 for declarators.
>
>>However, any of the enumerated
>>values is compatible with `int' because each *is* an `int'.
>
> Which is entirely irrelevant here: if the function declaration doesn't
> match the function definition, the behaviour is undefined:
>
> 2 All declarations that refer to the same object or function shall
> have compatible type; otherwise, the behavior is undefined.

    Aha! I think I understand the confusion, and my
elliptical advice was at least partly responsible for
it. I did not mean to suggest that the O.P should
declare his function as returning an int while defining
it to return an enum, but to declare and define it as
returning an int. I didn't say so explicitly, for much
the same reason I don't tell grownups to look both ways
when crossing streets.

    Declarations and definitions should agree, hence,
a (substantive) change to one should imply a corresponding
change to the other.

-- 
Eric.Sosman@sun.com


Relevant Pages

  • Re: whats the help of "unnecessary" pointer comparison?
    ... > i could not understand the "unnecessary" pointer comparison. ... the intent of line 214 is to ... ensure that _x and _y have compatible type by comparing their ... int x = -1; ...
    (comp.lang.c)
  • Immediate data
    ... Which types are immediates by default? ... It would be logical if they were of the largest compatible type.. ... FFFFFFFF, unsigned int ...
    (comp.lang.c)