Jump to content
  • Advertisement
Sign in to follow this  
danong

How to extend the functionality of C++?

This topic is 3593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am recently looking into the extensibility of the functionality in C++ language, so far, i couldn't figure out the way to actually get the things worked nicely. I am actually trying to do some add-on to the C++ function's returning type control with Assembly language, however i am stucked as i couldn't figure out which way to dive in. I wish to know if it is the right way to use Assembly to taking control of the things? Of which C++ is lacking of some functionality, which is i hope to redesign a class module for my own purpose, so could Assembly handle these things for me? Thanks in advance, Rgrds, Daniel.

Share this post


Link to post
Share on other sites
Advertisement
Just trying to achieve something that the older C++ (vc6++) couldn't achieve.
I am just wondering if it makes sense to use Assembly to expand the functionality & power of it.
Or is there a better way?

Share this post


Link to post
Share on other sites
While you could actually use assembly and wrap it inside macros or forced inline functions, using assembly is generally evil. Either you will lock your users into x86/64-architecture, or you end up writing assembly for many cpu-architectures (e.g. ARM is very widespread). Additionally, if you want to support several compilers (gcc, icc, msvc++, codewarrior) you eventually have to support multiple [inline] assembler syntaxes. In short, assembler makes your changes unportable.

Are you sure the changes you want to make can't be achieved by clever and clean c++ code?

Have you already checked ...
* C++ Templates - The Complete Guide (Vandevoorde, Josuttis)
* GoF [Design Patterns - Elements of Reusable Object-Oriented Software] (Gamma, Helm, Johnson, Vlissides)
* the boost libraries
* blitz++
?

Do you grok the "Guru of the Week" (gotw) articles?

Do you breath C++-03 and are you up to date (in knowledge) about C++0x?

If checked all (and a bit more), consider studying c++ compiler sourcecode (that is probably g++), and maybe write patches to add your features. Or rewrite a compiler from scratch (the latter will take you the next 5 years, at the minimum least and without the export keyword; c++ is not an LALR language and so somewhat full of ambiguities from the viewpoint of a compiler writer (how many interpretation do you find for (including template instantations)
Foo *bar; // multiply? pointer decl.?
Bar (baz); // Call? Constructor? Typecast? Function Prototype?

?)).


Another solution would be an add-on, a kind of macro processor, to be placed on top of c++. But I personally wouldn't use it for many reasons.


edit: Out of curiousity, what feature do you miss exactly?

[Edited by - phresnel on January 5, 2009 9:05:19 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by danong
Or is there a better way?
Upgrade to a newer compiler - VC6 is almost universally recognised as one of the worst compilers in existence.

Share this post


Link to post
Share on other sites
Quote:
Original post by danong
Or is there a better way?
There are about three dozen "better ways", depending on what it is you're trying to do, what compiler or compilers you're targeting, and what particular brand of ugliness most appeals to you. Messing around with the actual grammar of C++, though, is likely to be a non-starter; C++ front ends are just too damn complicated for anyone to work with of their own free will. To echo everyone else: What exactly are you trying to accomplish?

Share this post


Link to post
Share on other sites
Thanks all for the reply and helps (appreciated).

Okay, frankly i'd found out that C++ doesn't support multiple-type-return from the function, either it must be different-type-return value + different-type-parameter to actually ask the compiler to tell what is the difference.

And the engine i'm designing somehow needs this kind of functionality, i mean stay the same with the parameter, but only different type return value, however it's not achievable.

and for some reasons, i'm using somesort of code like this :

 
int foo::operator [] (const int index);
char foo::operator [] (const int index); // compiler couldn't work on this.




And so this is the reason i'm trying to deal with the front-end of the C++ compiler.

But now i'd found out that <typeinfo.h> could give me sth that i want,
but couldn't find the <typeinfo.cpp> source,
perhaps i'm wrong ;(

Perhaps i will just figure out another way of fixing this.



Thanks once again in advance.

Share this post


Link to post
Share on other sites
Quote:
Original post by danong
operator [] overloading doesn't support multiple parameters , i had tried that once. ;(


Why do you need to overload the [] operator?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!