home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!wupost!spool.mu.edu!yale.edu!jvnc.net!newsserver.technet.sg!nuscc!papaya!suresh
- From: suresh@papaya.iss.nus.sg (Suresh Thennarangam - Research Scholar)
- Subject: Sizeof and Virtual functions
- Message-ID: <1992Dec24.061254.9763@nuscc.nus.sg>
- Originator: suresh@papaya
- Sender: usenet@nuscc.nus.sg
- Organization: Institute of Systems Science, NUS, Singapore
- Date: Thu, 24 Dec 1992 06:12:54 GMT
- Lines: 41
-
- One of the things that distinguishes virtual functions from other
- normal member functions of a class is that some compilers that I
- know of, store an extra pointer that is probably used to index
- a vector table. This is done to facilitate late binding
- at run-time depending on the type of the object being pointed to
- rather than the type of the object pointer as opposed to normal
- member functions calls which are bound at compile time.
-
-
- Is this an implementation-specific issue only ?
-
- A C++ programmer should not have to know of these ugly little pointers
- lurking around in his structures. These monsters add 4 bytes each
- (on a 32 bit machine) to your structure; sizeof no longer tells the
- truth and seemingly innocent actions like fwrite'ing such structures
- to a file can quickly assume rather pernicious connotations.
-
- If I write classes with virtual functions to interpret and save
- file formats like XWD, TIFF, GIF , etc and innocently use sizeof()
- to calculate the size and write to a file I will be writing along
- addresses in my machines data area. Obviously, no one will be able
- to read those files either. Of course an experienced C++ programmer
- would know how work around this problem but this just an illustration.
-
- Isn't there a better way to implement virtual functions ?
- Isn't the current implementation a clever hack at best ?
-
-
- __
- (_ / / o_ o o |_
- __)/(_( __) (_(_ /_)| )_
-
-
- ***************************************************************************
- * Suresh Thennarangam * EMail: suresh@iss.nus.sg(Internet) *
- * Research Scholar * ISSST@NUSVM.BITNET *
- * Institute Of Systems Science * Tel: (065) 772 2588. *
- * National University Of Singapore * Facs.: (065) 778 2571 *
- * Heng Mui Keng Terrace * Telex: ISSNUS RS 39988 *
- * Singapore 0511. * *
- ***************************************************************************
-