This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Overlapping class members


Overlapping class members

Postby jont » Aug 26, 2003 @ 6:36pm

Here's the deal - I have two one 16bit member variable, and two 8bit member variables within a C++ class.

Rather than each one occupy it's own position in memory, I'd like all three to share the same 16bit space as follows:

- The 16bit variable should reside at memory location X.
- The first 8bit variable should reside at memory location X.
- The second 8bit variable should reside at memory location X+1.

Therefore:

- Changing the value of the 16bit variable will change the value of both 8bit variables
- Changing the value of the first 8bit variable will change the value of the low byte of the 16bit variable
- Changing the value of the second 8bit variable will change the value of the high byte of the 16bit variable

I know this is possible in some way or another using unions, but I'm after a way of doing things where I don't have to place the variables within a structure.

Any ideas appreciated, however wacky!

Cheers

Jon
User avatar
jont
pm Member
 
Posts: 122
Joined: Jul 16, 2002 @ 5:12pm
Location: Leeds, England


Postby Pejo Software - Per » Aug 26, 2003 @ 7:15pm

User avatar
Pejo Software - Per
pm Insider
 
Posts: 343
Joined: Apr 25, 2002 @ 1:00pm
Location: Mölndal, Sweden


Postby Pam » Aug 26, 2003 @ 7:57pm

All the easy problems have been solved.
User avatar
Pam
pm Insider
 
Posts: 449
Joined: Jan 24, 2002 @ 10:30pm
Location: Ohio


Postby refractor » Aug 26, 2003 @ 8:17pm

User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby jont » Aug 27, 2003 @ 10:20am

Thanks for the replies folks.

I'm already aware of the bit shifting and pointer solutions - I'm currently using the pointer solution but I'm concerned about the overhead of fetching the pointer variable every time I want to retrieve the value.

Ref: I'm interested to see what sort of assembly would be generated by the anon class types solution. Like the pointer solution, I'm concerned that the compiler may produce additional code to what it needs to generate.
User avatar
jont
pm Member
 
Posts: 122
Joined: Jul 16, 2002 @ 5:12pm
Location: Leeds, England


Postby Orpe » Aug 27, 2003 @ 11:40am

User avatar
Orpe
pm Member
 
Posts: 78
Joined: Sep 16, 2001 @ 6:51pm
Location: Stockholm, Sweden


Postby Ref » Aug 27, 2003 @ 12:42pm

Ref
 


Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron