home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18386 < prev    next >
Encoding:
Text File  |  1992-12-24  |  2.5 KB  |  53 lines

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