home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!gatech!usenet.ins.cwru.edu!po.CWRU.Edu!exk11
- From: exk11@po.CWRU.Edu (Erik Kangas)
- Subject: Re: ".", "->" operators and member data declarations
- Message-ID: <1992Jul22.212652.26091@usenet.ins.cwru.edu>
- Sender: news@usenet.ins.cwru.edu
- Nntp-Posting-Host: cwns1.ins.cwru.edu
- Reply-To: exk11@po.CWRU.Edu (Erik Kangas)
- Organization: Case Western Reserve University, Cleveland, OH (USA)
- References: <1992Jul21.141038.20704@usenet.ins.cwru.edu>
- Date: Wed, 22 Jul 92 21:26:52 GMT
- Lines: 64
-
-
- In a previous article, exk11@po.CWRU.Edu (Erik Kangas) says:
-
- >
- > I'm writing a memory management class in borland c++ that has
- >access to XMS, EMS and VDISK memory and handles it transparently
- >with conventional memory via handles.
- > However, To handle structures in memory, I currently have to
- >set up a number of constants relating to the byte offsets of the
- >data in the structure. Then add the byte offset to the handle using
- >an overloaded "+" operator like so...
- >
- >#define i 0
- >#define x 4
- >
- >struct foo {
- > long ident;
- > char xfer;
- > };
- >
- >.....
- >
- >Handle Fooptr = Malloc(sizeof(foo));
- >
- Handle is a class that contains info about where the data is stored - XMS,
- conventional memory, hard disk, Ems etc. Malloc is a friend of Handle.
- It allocates memory somewhere for use. The following operators are
- also overloaded "=" - to assign the value to some memory location
- or get it from some memory location, "+" to add an offset to the
- memory location. The following line is equivalent to
- *((char *)Fooptr + x) = 'P'; if Fooptr were a normal pointer, But
- it is actually a class object.
-
- >Fooptr + x = 'P';
- >
- >......
- >
- > I would like to use some operator, ( I know "." is reserved and "->"
- >only returns a pointer to the structure.) that would know the offset of
- >"xfer" in structure foo without me having to declare all the defines.
- >I should be able to do a "Fooptr.xfer = "P"".
- > Does anyone know of a built in way of transferring these offset values
- >and how I could tie them into overloaded operators?
- >
-
- I can't use normal pointer casting becuase I must assume that the data the
- caller wants is not in conventional memory. From within the object I
- must be able to "discover" the byte offset from the beginning of the
- structure and the variable type (or length) the user wants.
-
- Eg. if a statement was "Fooptr.x = 'P'" or something similar, I would
- need to find out that ".x" means the 4th byte from the beginning of the
- structure and that it is a char. Now the "." operator cannot be overloaded,
- so I'm not sure how to implement such as this.
-
- >Thank you.
- >
-
- --
- Erik Kangas
- Physics/Math/CompE "I lift up mine eyes unto the hills whence
- Phone 754-2316 cometh my strength" Psalms
- Zeta Psi #304 Whereof we cannot speak, Thereof we must be silent.
-