473,394 Members | 1,778 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,394 software developers and data experts.

C++ Runtime Defined Classes?

As I was reading through some of the stuff in the Standard, I started to
wonder if there might be reason to define classes in response to runtime
conditions, say, to match some kind of new data record format. It may be
an extremely overelaborate approach to problem solving, but it may also
have arguments in its favor. Does anybody know of a system which can
accept a class definition at runtime, compile it, then instantiate the
class in the running program?

What about runtime template processing?

No, not Emacs. I'm talking C++ here.
--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
Jul 22 '05 #1
6 4032
Steven T. Hatton wrote:
As I was reading through some of the stuff in the Standard, I started to
wonder if there might be reason to define classes in response to runtime
conditions, say, to match some kind of new data record format. It may be
an extremely overelaborate approach to problem solving, but it may also
have arguments in its favor. Does anybody know of a system which can
accept a class definition at runtime, compile it, then instantiate the
class in the running program?

[snip]

You would need a compiler on the target system. This is not as difficult
as it sounds -- Windows XP and up have at least the visual C++ .NET 2002
(even 2003, depending on what version of .NET is installed), Linux and
other unices generally have gcc. Or you could just distribute gcc with
your app.

The reason .NET ships with a C++ (and C#, VB.NET, etc) compiler in its
framework is that it takes this precise approach. In Reflection.Emit (I
think it's called) they take a String with the code, which is then
written out to a temporary file, compiled and a pointer to an
instantiated object of that class is returned. I believe -- I'm a little
rusty on the details.

There are two basic problems here:

1) You need a compiler on the platform, or you need to distribute your
own. It must work correctly. You must be able to interface with it
adequately. It must be standard conforming to the extent that you don't
have to worry too much about errors in standard code on every single
platform.

2) You must be able to interface with the generated code. To tell the
truth this is probably the hard part.

Oh, and don't forget that C++ compilers tend to be very slow (by
comparison to C#, for example) so this technique is probably not worth
the effort in the vast majority of cases.

-- Pete
Jul 22 '05 #2
Pete Vidler wrote:
Oh, and don't forget that C++ compilers tend to be very slow (by
comparison to C#, for example) so this technique is probably not worth
the effort in the vast majority of cases.


Thanks for the description. What I was thinking about would specifically
leverage MI. I don't know what C#'s object specification looks like, but I
suspect it doesn't provide for nearly as complex a class structure as one
can create in C++. Again, this may be overelaborate for any practical
application. OTOH, there may be practical uses for complex subobject
latices.
--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
Jul 22 '05 #3
"Steven T. Hatton" <su******@setidava.kushan.aa> wrote
As I was reading through some of the stuff in the
Standard, I started to wonder if there might be
reason to define classes in response to runtime
conditions, say, to match some kind of new data
record format.
There are cases where one might want to do that.
It may be an extremely overelaborate approach
to problem solving, but it may also have arguments
in its favor.
It's just another wrench in the generic programming toolkit. Just one that
C++ doesn't provide.
Does anybody know of a system which can accept
a class definition at runtime, compile it, then instantiate
the class in the running program?
LISP.
What about runtime template processing?
LISP.
No, not Emacs.
LISP works fine without EMACS. Always has.
I'm talking C++ here.


Then no. C++ does no support runtime code creation. What you can do is
programmatically generate the source files, invoke the compiler/linker to
build a shared library/DLL/component and then load/connect to the result.
You'd just better hope you don't need to use that class in the next few
milliseconds.

Claudio Puviani
Jul 22 '05 #4
Claudio Puviani wrote:
No, not Emacs.


LISP works fine without EMACS. Always has.


Actually, Mathematica smells a lot like Emacs/Lisp. But then so does J***,
not to mention that Mozilla is the offspring of XEmacs, using JavaScript as
Lisp in C atire. All of these tend toward runtime defintion and
instantiation to one degree or another.
I'm talking C++ here.


Then no. C++ does no support runtime code creation. What you can do is
programmatically generate the source files, invoke the compiler/linker to
build a shared library/DLL/component and then load/connect to the result.
You'd just better hope you don't need to use that class in the next few
milliseconds.


I know it heads off topic, but I'm wondering of anybody knows of research
along these lines. This idea seems to dovetail with the emerging template
metaprogramming school. http://www.boost.org/libs/mpl/doc/

--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
Jul 22 '05 #5
"Steven T. Hatton" <su******@setidava.kushan.aa> wrote
Claudio Puviani wrote:
No, not Emacs.
LISP works fine without EMACS. Always has.


Actually, Mathematica smells a lot like Emacs/Lisp.


It has a lot of overlap.
But then so does J***,
There isn't even a shred of resemblance between Java and LISP on any level.
If you ever say something like that in a LISP forum, do it anonymously
because someone will track you down and beat you senseless with parentheses.
not to mention that Mozilla is the offspring of XEmacs
Huh?
, using JavaScript as Lisp in C atire.
Great scott! Having a built-in list type does NOT make a language LISP-like!
All of these tend toward runtime defintion and
instantiation to one degree or another.


My copy of the Java language definition must be missing the chapter that
deals with runtime definition of classes.
I'm talking C++ here.


Then no. C++ does no support runtime code creation. What
you can do is programmatically generate the source files, invoke
the compiler/linker to build a shared library/DLL/component
and then load/connect to the result. You'd just better hope you
don't need to use that class in the next few milliseconds.


I know it heads off topic, but I'm wondering of anybody knows of research
along these lines. This idea seems to dovetail with the emerging template
metaprogramming school. http://www.boost.org/libs/mpl/doc/


Template metaprogramming is static. Dynamic type creation is a completely
different field with distinct problems, limitations, and solutions. It could
be implemented by opening access to the VMT (probably through a standard
API) so that you could build new ones or modify existing ones, but this is a
can of worms the size of Shai-Hulud.

Claudio Puviani
Jul 22 '05 #6
Claudio Puviani wrote:
"Steven T. Hatton" <su******@setidava.kushan.aa> wrote
Claudio Puviani wrote: <off-topic>
There isn't even a shred of resemblance between Java and LISP on any
level. If you ever say something like that in a LISP forum, do it
anonymously because someone will track you down and beat you senseless
with parentheses.
I do know one XEmacs maintainer who quipped that Gosling is the epitomy of
evil. But I don't think he would deny Java's origin. The XEmacs
documentation is rather explicit about it.
not to mention that Mozilla is the offspring of XEmacs


Huh?
, using JavaScript as Lisp in C atire.


Great scott! Having a built-in list type does NOT make a language
LISP-like!


There's more to it. I don't recall the details, but I read a discussion of
this a while back. Considering Zawinski and Andreessen were XEmacs
maintainers before starting Netscape Communication, there's more than
likely a connection. It's not just JavaScript either. It's pretty clear
to me the got the idea and knowhow for the event loop at the heart of
Mozilla (Mosaic -> Mozilla) from XEmacs.
All of these tend toward runtime defintion and
instantiation to one degree or another.


My copy of the Java language definition must be missing the chapter that
deals with runtime definition of classes.


JSP's been doing it for quite some time. But there is now a pretty solid
infrastruture for passing soucecode around to be compiled automatically on
remote systems using XML. So the literature says.
</off-topic>
Template metaprogramming is static. Dynamic type creation is a completely
different field with distinct problems, limitations, and solutions. It
could be implemented by opening access to the VMT (probably through a
standard API) so that you could build new ones or modify existing ones,
but this is a can of worms the size of Shai-Hulud.


Do you mean to say new templates or new classes being created dynaimcally? I
was thinking about using templates at runtime as, well, templates, and
passing type infromation to them, thus creating new types 'on the fly'
--
p->m == (*p).m == p[0].m
http://www.kdevelop.org
http://www.suse.com
http://www.mozilla.org
Jul 22 '05 #7

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

Similar topics

1
by: Hal Vaughan | last post by:
I've been using Runtime.exec() like this: Runtime rt = Runtime.getRuntime(); try {Process p = rt.exec("MyCommand.bat");} catch (Exception e) {do stuff} When I start my Java classes, I start...
6
by: Steven T. Hatton | last post by:
As I was reading through some of the stuff in the Standard, I started to wonder if there might be reason to define classes in response to runtime conditions, say, to match some kind of new data...
12
by: Daniel Bolege | last post by:
Hello, I've a problem that drives me crazy. There must be a simple solution, but I just can't see it. The following code is just a simple example that demonstrates my problem: I have an...
2
by: Jeffrey Ganping Chen | last post by:
I'm trying to build a generic runtime C# expression evaluation engine to allow the user to evaluate any C# code blocks at runtime within the application's context. For example, obj4.p4 =...
6
by: yohaas | last post by:
I'm trying to do something, not sure if it's possible or even if it makes sense, but I figured I'd throw it out there. I have a class OrderSummary that contains information about an order. I...
12
by: Markus Ewald | last post by:
I'm just experimenting around with the VisualC++ 2005 Express Edition Beta and found some strange behavior for which I can't seem to find a workaround. What I've done is set up two static library...
3
by: Dan | last post by:
Hi, I have a problem using an aspx page with a Control on it. I get the following error message Compiler Error Message: CS1595: 'Test.Class2' is defined in multiple places; using definition...
3
by: joannax | last post by:
Hi, I am an experienced programmer in several languages, but new to VB .NET. I am designing an application which consists of a single "menu" program/form that selectively transfers control to...
0
by: ahk3wl | last post by:
Hi all, I am consuming two web services that are identical but on different servers. The WSDL is the same except for URL and namespace. Normally I could just add a web reference and swap URL at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.