CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Faltering Windows support
  • Internet Explorer 8 Click Clever Click Safe
  • Release Candidate 2 for ASP.NET MVC 2
  • Learn How to Create Dual Mode Windows Services

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old October 11th, 2009, 03:26 PM
    bhushan1980 bhushan1980 is offline
    Member +
     
    Join Date: Jun 2006
    Posts: 609
    bhushan1980 will become famous soon enough (50+)
    C++ and reflection

    What is the exact reason that C++ lacks reflection? Now I know exactly, what reflection is and how it is achieved in other OOP languages. I know that it is used by the compiler to parse the classes, functions, objects,etc. in a C++ program.
    Why does a compiler need to do parsing at all? Pardon my lack of knowledge of inner workings of a compiler....
    I have heard that this parsing is useful to get type info at runtime. And I have also heard people say that this parser breaks while working with C++. Why does it happen?
    Is intellisense feature -? Auto completion is completely based upon reflection?
    Please comment...
    Thanks and Regards.
    Bhushan
    Reply With Quote
      #2    
    Old October 11th, 2009, 11:02 PM
    originalfamousjohnsmith originalfamousjohnsmith is offline
    Member
     
    Join Date: Aug 2009
    Posts: 94
    originalfamousjohnsmith is an unknown quantity at this point (<10)
    Re: C++ and reflection

    Quote:
    Originally Posted by bhushan1980 View Post
    What is the exact reason that C++ lacks reflection? Now I know exactly, what reflection is and how it is achieved in other OOP languages. I know that it is used by the compiler to parse the classes, functions, objects,etc. in a C++ program.
    Why does a compiler need to do parsing at all? Pardon my lack of knowledge of inner workings of a compiler....
    I have heard that this parsing is useful to get type info at runtime. And I have also heard people say that this parser breaks while working with C++. Why does it happen?
    Is intellisense feature -? Auto completion is completely based upon reflection?
    Please comment...
    Thanks and Regards.
    Bhushan
    It's just slow and it takes extra space, as well. But these days there is not much excuse not to have it as you would not need to generate it for all objects anyway.

    It's not bad for largish objects like you see in many database apps but for small objects it causes problems.

    There is RTTI in C++ but if I remember properly it doesn't really give as much info and is not on by default.

    By parser I think you mean C#, and it fails because C++ structures don't have the info it needs.
    Reply With Quote
      #3    
    Old October 12th, 2009, 09:58 AM
    bhushan1980 bhushan1980 is offline
    Member +
     
    Join Date: Jun 2006
    Posts: 609
    bhushan1980 will become famous soon enough (50+)
    Re: C++ and reflection

    Well...How did I miss that? Actually I was referring to parser in C# and the autocompletion feature that exists for it (and other IDEs). I am wondering, if it is so hard for MS to provide auto-completion for C++ in VS IDE, how come Visual Assist does it? I have not used it personally but have seen it recommended on CG posts and also I have seen it working on some videos and screenshots. However, it is ironical to find out that it is little hard for MS to develop the feature themselves for their own product, since the past 2 versions VS 2005/2008 and forth coming VS 2010 (which lacks this feature for C++ as well) or overlook it completely, while a third party provides the same for successive versions without any problems....
    Parsing and autocompletion are not the only issues that are on my mind. There are a lot of benefits of having reflection support and the list which I need not put down here...At the sametime, I also agree that it is difficult to provide looking at the compile architecture of C++; which is ofcourse highly optimized.
    On doing some research, I found out that, what reflection enables a compiler to do is obtain the info for all the classes that are linked in the inheritance list and this list starts from a class in the final output which is an exe or a dll (assembly in .NET) and goes back till the root class. The way the C++ compiler works is highly optimized and hence one of the things it does in favor goes against it providing reflection capabilities. It simply excludes the classes from the exe or dll that were never used. On the other hand a C# compiler provides a guaruntee that the class exists no matter what happens. Thus C# helps parsing its metadata very easy and C++ compiler asks a lot more Qs. So if a parser / reflector (or whatever tool that provides reflection) tries to find a missing class and it does not find one, it fails miserably. There might be work around for this, but I am not aware of any. I read that a simple template instantiation is followed by a large number of subsequent calls to other classes / function templates; hence one can imagine the magnitude of work that has to be done to get the information of all those classes. This is all because, unlike C#, the native C++ applications do not have the CLR facility.
    Now there is a counter argument, as "originalfamousjohnsmith" said before, that C++ developers have not really cared about reflection as it unnecessarily increases the resources required any which ever form. But, my counter argument is, why not do some research and provide reflection separately and a switch that helps user decide whether to use it or not? The switch can be integrated in the compiler / linker options or can be defined from the code using various macros. That way, a user has it, if needed.
    Also, surprisingly, C++0x standards committee has not got any plans to include it in the forth coming standards. I wonder, if they are trying to make C++ a better language from commercial point of view as againts as an ideal language. And MS, sadly as usual, has been complaining about the difficulty that is faced while providing the same. I saw a video that had demoed the VS 2010 IDE features for C++ developers. Even while the person, who was supposed to be on the team to improve the IDE features that are presented to C++ developers, was demoing the features, atleast half of his claims were refuted by the IDE in front of the masses. I am not mocking or offending anyone by stating this and I am sorry if it sounds like it. One thing that was good, that MS did that needs to be mentioned was the removing of .ncb files; not related to this thread though.
    Regards,
    Bhushan
    Reply With Quote
      #4    
    Old October 12th, 2009, 10:34 AM
    Alex F's Avatar
    Alex F Alex F is offline
    Senior Member
     
    Join Date: Jul 2002
    Posts: 1,663
    Alex F is a splendid one to behold (750+) Alex F is a splendid one to behold (750+) Alex F is a splendid one to behold (750+) Alex F is a splendid one to behold (750+) Alex F is a splendid one to behold (750+) Alex F is a splendid one to behold (750+) Alex F is a splendid one to behold (750+)
    Re: C++ and reflection

    Not sure, where are you talking about Intellisence, and where about Reflection.
    Intellisence: in native C++, it works pretty well in VS2005 and later. In C++/CLI it almost doesn't work, even in VS2100.
    About Reflection: if you really need it in C++, use C++/CLI. Native C++ remains highly optimized, and doesn't support such things. I think this is good, because there are still developers who need real-time performance.
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 09:55 AM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.