Article View: comp.sys.mac.programmer.codewarrior
Article #714Preserving class member-variable order?
From: Michael
Date: Thu, 07 Aug 2003 23:12
Date: Thu, 07 Aug 2003 23:12
31 lines
2285 bytes
2285 bytes
Hi,
I'm dev'ing in C++ using Codewarrior 8.3, on OS 9.2 & X.
I'm trying to find out if there's a way to preserve the order of class
member variables, ie the order in which they are listed in the class
declaration. I'm hoping to be able to reference a class member indirectly by
deref'ing another class member that is a known distance away. I've done this
before on Windows (VC++) and it works nicely, but the same approach doesn't
seem to work in OS 9 (or maybe because of the CW compiler?). I haven't tried
yet on OS X but I imagine it might be the same on OS 9?
A simple example is below. This simple example might work, but I've been
trying to get it to work in a much larger class. I haven't tested
extensively, thinking that someone might have a quick answer for me.
class MyClass{
char interestingValue;
char placeHolder;
}
MyClass obj;
char val = *(&(obj.placeHolder)-1);
I was thinking there might be a compiler option or pragma I could use to fix
the order of the members during compilation. Does anyone have any
suggestions?
Many thanks,
Michael
Technical Details
Message-ID:
<r1BYa.1145$014.1012@nwrdny02.gnilink.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!wn11feed!worldnet.att.net!199.45.49.37!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny02.gnilink.net.POSTED!53ab2750!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10bcce,e09790fdeb4be6df,start X-Google-Attributes: gid10bcce,public X-Google-Thread: f635e,e09790fdeb4be6df,start X-Google-Attributes: gidf635e,public X-Google-ArrivalTime: 2003-08-07 16:12:24 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!wn11feed!worldnet.att.net!199.45.49.37!cyclone1.gnilink.net!spamkiller2.gnilink.net!nwrdny02.gnilink.net.POSTED!53ab2750!not-for-mail From: "Michael" <mstauff@bellatlantic.net> Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac Subject: Preserving class member-variable order? Lines: 33 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4920.2300 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4920.2300 Message-ID: <r1BYa.1145$014.1012@nwrdny02.gnilink.net> Date: Thu, 07 Aug 2003 23:12:23 GMT NNTP-Posting-Host: 151.197.16.150 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny02.gnilink.net 1060297943 151.197.16.150 (Thu, 07 Aug 2003 19:12:23 EDT) NNTP-Posting-Date: Thu, 07 Aug 2003 19:12:23 EDT