Article View: comp.os.msdos.programmer
Article #2552Re: TC++ 1.0 Loses Type Information? (In English)
From: Barry L. Wallis
Date: Thu, 04 Oct 1990 20:58
Date: Thu, 04 Oct 1990 20:58
46 lines
2245 bytes
2245 bytes
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"
---
Technical Details
Message-ID:
<15810@shlump.nac.dec.com>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!aplcen!samsung!cs.utexas.edu!rutgers!mcnc!decvax.dec.com!shlump.nac.dec.com!labc.enet.dec.com!wallisShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!aplcen!samsung!cs.utexas.edu!rutgers!mcnc!decvax.dec.com!shlump.nac.dec.com!labc.enet.dec.com!wallis From: wallis@labc.enet.dec.com (Barry L. Wallis) Newsgroups: comp.os.msdos.programmer Subject: Re: TC++ 1.0 Loses Type Information? (In English) Summary: Turbo C++ V1.0 is acting correctly Message-ID: <15810@shlump.nac.dec.com> Date: 4 Oct 90 20:58:18 GMT Sender: newsdaemon@shlump.nac.dec.com Organization: Digital Equipment Corporation Lines: 46