473,320 Members | 2,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to implement reflection in C++

Java, C# and other languages allow one to enumerate all the data
members of a class or struct thru their respective reflection APIs.

Varios Microsoft specific extensions to their C++ compiler allows one
to do the same (I'm thinking of both the COM extentions as wells as the
managed extensions).

I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?

Thanks,
Siegfried

Nov 27 '05 #1
7 2317

Siegfried wrote:
Java, C# and other languages allow one to enumerate all the data
members of a class or struct thru their respective reflection APIs.

Varios Microsoft specific extensions to their C++ compiler allows one
to do the same (I'm thinking of both the COM extentions as wells as the
managed extensions).

I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?


I'm gonna bet that such a thing isn't available. Maybe if you explain
why you need it, or think you need it, someone could help you find a
more available solution.

Nov 27 '05 #2
Siegfried wrote:
Java, C# and other languages allow one to enumerate all the data
members of a class or struct thru their respective reflection APIs.

Varios Microsoft specific extensions to their C++ compiler allows one
to do the same (I'm thinking of both the COM extentions as wells as the
managed extensions).

I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?


have a look at the objdump(1) sources which reads symbols from gcc
generated object files.

but i don't think you will be able to get the information that you need
from the object files, as these linker input files do not necessarily
contain the original C++ object layout in processable form.

you will need C++ parser output to get full identifier information for
C++ source files.

if you don't want to use a full-blown C++ parser implementation, for
example the wrapper/interface generator tool swig has a mode to output
a XML or lisp s-expression formatted abstract syntax tree for given
source files. this gives you parseable data to further work with.

see http://www.swig.org

-- peter

Nov 27 '05 #3
On 27 Nov 2005 01:51:05 -0800, "peter steiner" <pn*******@gmail.com>
wrote:
Siegfried wrote:
Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?


have a look at the objdump(1) sources which reads symbols from gcc
generated object files.


or nm
(http://www.gnu.org/software/binutils...inutils_2.html)
on Unix or dumpbin for VC++.

Best wishes,
Roland Pibinger
Nov 27 '05 #4
Siegfried wrote:
I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?


Supposing that you find or write such a tool, you must consider that the
member functions of a class can be spawned over several .o files.

--
Salu2
Nov 27 '05 #5
Siegfried wrote:
Java, C# and other languages allow one to enumerate all the data
members of a class or struct thru their respective reflection APIs.

Varios Microsoft specific extensions to their C++ compiler allows one
to do the same (I'm thinking of both the COM extentions as wells as the
managed extensions).

I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?

Go ask the gcc people. It's not standard C++ (I wish it was too) so
it's off topic here.
Nov 27 '05 #6
Take a look at the RTTI chapter in Thinking in C++
(www.bruceeckel.com), i don't remember which volume.

Nov 28 '05 #7

"peter steiner" <pn*******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Siegfried wrote:
Java, C# and other languages allow one to enumerate all the data
members of a class or struct thru their respective reflection APIs.

I don't believe g++ supports either of these. Does anyone have some
sample code that will read a g++ .o file (that was compiled with the
debug option turned on), or a g++ executable image and extract the meta
data about a type so I can enumerate the datamembers?


you will need C++ parser output to get full identifier information for
C++ source files.


A front end C++ parser that can be straightforwardly configure to do this
can be seen at
http://www.semanticdesigns.com/Produ...ds/CppFrontEnd
It handles full GCC.
--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com
Dec 7 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jonathan | last post by:
hey all, I'd like to implement an application that is truly dynamic: the components are not only just known at runtime, but also the components are unknown at runtime: ie: some don't even ship...
2
by: Thorsten Tarrach | last post by:
Hallo, The best thing would be to implement a trace call in every procedure to write an entry in the log file: If MySwitch.TraceVerbose() then trace.writeline("Procedure xyz started with...
1
by: Rhett | last post by:
Hello,EveryBody! I'm troubled by a design problem, Hoping that you'll save me out! The Situation is: We have two project of code A and B.A is our reusable code base, B is for specified for...
3
by: ATS | last post by:
HOWTO Implement LoadLibrary, GetProcAdress, and FreeLibrary. Below is code that I want to be able to use simple LoadLibrary\GetProcAddress\FreeLibrary technqiues on. I've used the code that was...
3
by: Rud | last post by:
I'm still searching for an easy way to implement customized mouse pointers. I've searched in the help text but couldn't get the answer. Do I have to dig into the creation of resource files or is...
5
by: g18c | last post by:
Hi, im trying to do something and just been caught off guard. I want to implement an interface but only for certain class, but of course when i derive from this base class the derived class also...
5
by: ohmmega | last post by:
simple question: is there a easy way to implement different user levels (hiding buttons and such stuff)? regards rené p.
6
by: Smithers | last post by:
Just looking to compile a list of "all the ways to implement events". I'm NOT looking to get into the merits or mechanics of each in this thread... just want to identify them all - good, bad, and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.