home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11347 < prev    next >
Encoding:
Text File  |  1992-07-22  |  2.8 KB  |  77 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!gatech!usenet.ins.cwru.edu!po.CWRU.Edu!exk11
  3. From: exk11@po.CWRU.Edu (Erik Kangas)
  4. Subject: Re: ".", "->" operators and member data declarations
  5. Message-ID: <1992Jul22.212652.26091@usenet.ins.cwru.edu>
  6. Sender: news@usenet.ins.cwru.edu
  7. Nntp-Posting-Host: cwns1.ins.cwru.edu
  8. Reply-To: exk11@po.CWRU.Edu (Erik Kangas)
  9. Organization: Case Western Reserve University, Cleveland, OH (USA)
  10. References: <1992Jul21.141038.20704@usenet.ins.cwru.edu>  
  11. Date: Wed, 22 Jul 92 21:26:52 GMT
  12. Lines:       64
  13.  
  14.  
  15. In a previous article, exk11@po.CWRU.Edu (Erik Kangas) says:
  16.  
  17. >
  18. >   I'm writing a memory management class in borland c++ that has
  19. >access to XMS, EMS and VDISK memory and handles it transparently
  20. >with conventional memory via handles.
  21. >   However, To handle structures in memory, I currently have to 
  22. >set up a number of constants relating to the byte offsets of the
  23. >data in the structure.  Then add the byte offset to the handle using
  24. >an overloaded "+" operator like so...
  25. >
  26. >#define i 0
  27. >#define x 4
  28. >
  29. >struct foo {
  30. >    long ident;
  31. >    char xfer;
  32. >    };
  33. >
  34. >.....
  35. >
  36. >Handle Fooptr = Malloc(sizeof(foo));
  37. >
  38. Handle is a class that contains info about where the data is stored - XMS,
  39.    conventional memory, hard disk, Ems etc.  Malloc is a friend of Handle.
  40.    It allocates memory somewhere for use.  The following operators are
  41.    also overloaded "=" - to assign the value to some memory location
  42.    or get it from some memory location, "+" to add an offset to the
  43.    memory location.  The following line is equivalent to
  44.    *((char *)Fooptr + x) = 'P';  if Fooptr were a normal pointer,  But
  45.    it is actually a class object.
  46.  
  47. >Fooptr + x = 'P';
  48. >
  49. >......
  50. >
  51. >    I would like to use some operator, ( I know "." is reserved and  "->"
  52. >only returns a pointer to the structure.) that would know the offset of
  53. >"xfer" in structure foo without me having to declare all the defines.
  54. >I should be able to do a "Fooptr.xfer = "P"".
  55. >    Does anyone know of a built in way of transferring these offset values
  56. >and how I could tie them into overloaded operators?
  57. >
  58.  
  59. I can't use normal pointer casting becuase I must assume that the data the
  60. caller wants is not in conventional memory.  From within the object I
  61. must be able to "discover" the byte offset from the beginning of the 
  62. structure and the variable type (or length) the user wants.
  63.  
  64.     Eg.  if a statement was "Fooptr.x = 'P'" or something similar, I would
  65. need to find out that ".x" means the 4th byte from the beginning of the
  66. structure and that it is a char.  Now the "." operator cannot be overloaded,
  67. so I'm not sure how to implement such as this.  
  68.  
  69. >Thank you.
  70. >
  71.  
  72. -- 
  73. Erik Kangas  
  74. Physics/Math/CompE         "I lift up mine eyes unto the hills whence  
  75. Phone 754-2316              cometh my strength"  Psalms                
  76. Zeta Psi #304               Whereof we cannot speak, Thereof we must be silent.
  77.