[comp.os.msdos.programmer] TC++ 1.0 Loses Type Information?

kutner@vid.cpg.sony.co.jp (Mike Kutner) (10/02/90)

The following code fragment gives a "Suspicious pointer conversion"
warning message when compiled by Turbo C++ 1.0 (in C mode).  It seems
that the structure member's type information is getting lost.  An
explicit cast (enum day_t *) gets rid of the warning message.  However,
am I being dense or has someone else seen this problem?

enum day_t {mon, tue, wed, thu};

struct date_t
{
    enum day_t day;
};

void foo(enum day_t *dtp)
{
    *dtp = tue;
}

void main(void)
{
    struct date_t bar;

    foo(&(bar.day));	/* <--- Suspicious pointer conversion */
}

kutner@vid.cpg.sony.co.jp

--
----
Mike Kutner                             From the US: kutner@vid.cpg.sony.co.jp
Sony Corporation Atsugi Technology Center                 Tel: +81-462-30-5705
4-14-1 Asahi-cho, Atsugi-shi, Kanagawa-ken 243 Japan

kdq@demott.COM (Kevin D. Quitt) (10/03/90)

In article <2019@cpgvgw.vid.cpg.sony.co.jp> kutner@vid.cpg.sony.co.jp (Mike Kutner) writes:
>The following code fragment gives a "Suspicious pointer conversion"
>warning message when compiled by Turbo C++ 1.0 (in C mode).  It seems
>that the structure member's type information is getting lost.  An
>explicit cast (enum day_t *) gets rid of the warning message.  However,
>am I being dense or has someone else seen this problem?
>
>enum day_t {mon, tue, wed, thu};
>
>struct date_t
>{
>    enum day_t day;
>};
>
>void foo(enum day_t *dtp)
>{
>    *dtp = tue;
>}
>
>void main(void)
>{
>    struct date_t bar;
     ^^^^^^_________________Shouldn't this be enum?

>
>    foo(&(bar.day));	/* <--- Suspicious pointer conversion */
>}
>

-- 
 _
Kevin D. Quitt         demott!kdq   kdq@demott.com
DeMott Electronics Co. 14707 Keswick St.   Van Nuys, CA 91405-1266
VOICE (818) 988-4975   FAX (818) 997-1190  MODEM (818) 997-4496 PEP last

                96.37% of all statistics are made up.

russw@cs.utexas.edu (Russ Williams) (10/03/90)

Yes, there is a bug in TC++ 1.0 that gives a spurious Suspicious Pointer
COnversion for pointer-to-enum parameters.
--Russ

wallis@labc.enet.dec.com (Barry L. Wallis) (10/05/90)

In article <2019@cpgvgw.vid.cpg.sony.co.jp>, kutner@vid.cpg.sony.co.jp (Mike Kutner) writes...
!>The following code fragment gives a "Suspicious pointer conversion"
!>warning message when compiled by Turbo C++ 1.0 (in C mode).  It seems
!>that the structure member's type information is getting lost.  An
!>explicit cast (enum day_t *) gets rid of the warning message.  However,
!>am I being dense or has someone else seen this problem?
!> 
!>enum day_t {mon, tue, wed, thu};
!> 
!>struct date_t
!>{
!>    enum day_t day;
!>};
!> 
!>void foo(enum day_t *dtp)
!>{
!>    *dtp = tue;
!>}
!> 
!>void main(void)
!>{
!>    struct date_t bar;
!> 
!>    foo(&(bar.day));	/* <--- Suspicious pointer conversion */
!>}
!> 
!> 

Turbo C++ V1.0 is acting correctly (at least as far as C++ is concerned; I know
you are in C mode, but, this may help as the logic makes sense in either
language). According to the ARM (_Annotated C++ Reference Manual_ by Ellis and
Stroustrup) section 7.2 explains that "Each enumeration defines an integral
type that is different from all other integral types." It then goes on to
explain that although you cannot assign an int directly to an enum you can use
a cast to force the assignment. However, in this case you losethe C++ strong
type checking facility and can assign a "bad" value to the enum.

So, the structure member's type information is not getting lost, it is being
enforced. The only question I have is should this be happening in C mode?
---
Barry L. Wallis			USENET: wallis@labc.dec.com
Database Consultant		Prodigy (don't laugh): DNMX41A
U.S. DECtp Resource Center	DECUServe: EISNER::WALLIS (not on the net yet)
Los Angeles, CA			"No one voted for me, I represent myself"
---

dfoster@jarthur.Claremont.EDU (Derek R. Foster) (10/07/90)

In article <640@demott.COM> kdq@demott.COM (Kevin D. Quitt) writes:
>In article <2019@cpgvgw.vid.cpg.sony.co.jp> kutner@vid.cpg.sony.co.jp (Mike Kutner) writes:
>>The following code fragment gives a "Suspicious pointer conversion"
>>warning message when compiled by Turbo C++ 1.0 (in C mode).  It seems
>>that the structure member's type information is getting lost.  An
>>explicit cast (enum day_t *) gets rid of the warning message.  However,
>>am I being dense or has someone else seen this problem?


I've seen this problem. And, to answer a couple of previous poster's
suggestions, the problem is not merely dependant on whether the
enum in question is a member of a struct/class or not. I've had
this problem with global variables too. I think it's a bug in TC++.
MSC v. 5.1 passed my code without complaint, but TC++ complains.

Also: in reply to another poster's response that the difference is caused
by the way C++ treats enums: I don't see any reason why the difference
between enum and int which is enforced by C++ (but not C) should make
any difference in whether a pointer to an enum type should be able to
be passed via a function call to a pointer of the same type. I could see
problems created if one or the other was a normal int perhaps, but that
was not the case here. Perhaps I am misunderstanding you?

Derek Riippa Foster