Thread: Microsoft -> ISO conversion problem

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    8

    Microsoft -> ISO conversion problem

    I'm having some problems getting some code (which I believe is compliant to the Microsoft C++ definition) to compile on CodeWarrior (which uses is ISO definition). I've sorted some of the syntax errors out but I'm stumped by this one:

    Code:
    inline T* GetNext(const T* a_elem) const { return (T*) _elem->gmListDoubleNode<T>::m_next; }
    I'm getting an exception saying that it expects an open bracket at ..eNode<T>...

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Which version of MSVC are you using? The later versions (2005, 2008) should be pretty well compliant with the ISO standard. Older versions may lack to a greater extent.

    It would help a huge amount if you could post a complete compilable example (for this case, I suspect you only need about 5-10 lines of code, give or take a bit) - then others can try to compile the code in various compilers they have access to.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Microsoft may be large, but it doesn't get its own C++ (any more than gcc gets its own C++) -- there are extensions, of course, and you can switch them off to check whether you use them or not.

    Anyway, I don't see much on this line (maybe _elem should be a_elem, since that's what you're passing into the function?). It's hard to tell without some declarations.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    What is gmListDoubleNode and why does it have a template argument?
    If it's a typedef for something, you probably need to specify a typename keyword. But from the way it's used, it doesn't look like it could be a type.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    Quote Originally Posted by murdercityriot View Post
    I'm having some problems getting some code (which I believe is compliant to the Microsoft C++ definition) to compile on CodeWarrior (which uses is ISO definition). I've sorted some of the syntax errors out but I'm stumped by this one:

    Code:
    inline T* GetNext(const T* a_elem) const { return (T*) _elem->gmListDoubleNode<T>::m_next; }
    I'm getting an exception saying that it expects an open bracket at ..eNode<T>...
    maybe >: is a digraph, try putting a space in there

  7. #7
    Registered User
    Join Date
    Aug 2008
    Posts
    8
    Quote Originally Posted by KIBO View Post
    maybe >: is a digraph, try putting a space in there
    Nope, no luck unfortunately

  8. #8
    Registered User
    Join Date
    Aug 2008
    Posts
    8

    Talking

    Sorry! My wrists are well and truly slapped

  9. #9
    Registered User
    Join Date
    Aug 2008
    Posts
    8
    Quote Originally Posted by matsp View Post
    Which version of MSVC are you using? The later versions (2005, 2008) should be pretty well compliant with the ISO standard. Older versions may lack to a greater extent.

    It would help a huge amount if you could post a complete compilable example (for this case, I suspect you only need about 5-10 lines of code, give or take a bit) - then others can try to compile the code in various compilers they have access to.

    --
    Mats
    Thanks for your help, I'm trying to get the GameMonkey scripting tools to compile with my program, so it's a bit difficult to give a compilable example as I'm not that familiar with their codebase.

    I've isolated the problem as being whenever a template <T> is used before a ::

    If I remove the <T>, it compiles fine (although obviously doesn't work correctly).

    Another example is:

    Code:
    T * GetNext(T * a_elem) const { return a_elem->gmHashNode<KEY, T,HASHER>::m_next; }

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The later versions of MSVC handles such cases just fine.
    Make sure your version is up-to-date. And we still don't know even remotely what can be causing your problem.
    How does the template declaration part before the function look like?
    What is the type of a_elem (I know it's T, but what type is T?)?
    Is the member function gmHashNode a template member function or a normal member function inside a template class or some such?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    The later versions of MSVC handles such cases just fine.
    Make sure your version is up-to-date. And we still don't know even remotely what can be causing your problem.
    How does the template declaration part before the function look like?
    What is the type of a_elem (I know it's T, but what type is T?)?
    Is the member function gmHashNode a template member function or a normal member function inside a template class or some such?
    I may have contributed to the confusion - the original poster is actually usign a metroworks compiler to compile the code - it compiles correctly on MS [as far as I can understand].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User
    Join Date
    Aug 2008
    Posts
    8
    Quote Originally Posted by Elysia View Post
    The later versions of MSVC handles such cases just fine.
    Make sure your version is up-to-date. And we still don't know even remotely what can be causing your problem.
    How does the template declaration part before the function look like?
    What is the type of a_elem (I know it's T, but what type is T?)?
    Is the member function gmHashNode a template member function or a normal member function inside a template class or some such?
    I'm not using MSVC, I'm using the ISO compliant CodeWarrior compiler.

    I'm not sure what you mean about the type of a_elem.

    Thanks for your help, I've included more code so you can see what the template declaration etc. looks like:

    Code:
    /// \class gmListDouble
    /// \brief Templated intrusive doubly linked list using a sentinal node
    template <class T>
    class gmListDouble
    {
    public:
    
      /// \class Iterator
      class Iterator
      {
      public:
    
        GM_INCLUDE_ITERATOR_KERNEL(T)
    
        inline Iterator() { m_node = NULL; m_list = NULL; }
        inline Iterator(T * a_node, const gmListDouble * a_list) { m_node = a_node; m_list = a_list; }
    
        inline void Inc() { m_node = m_list->GetNext(m_node); }
        inline void Dec() { m_node = m_list->GetPrev(m_node); }
        inline bool IsValid() const { return (m_list && m_list->IsValid(m_node)); }
    
      private:
    
        T * m_node;
        const gmListDouble * m_list;
      };
    
      // methods
    
      inline gmListDouble();
      inline ~gmListDouble();
    
      inline void InsertAfter(T * a_cursor, T * a_elem);
      inline bool IsValid(const T* a_elem) const { return (a_elem != &m_sentinel); }
      inline T* GetFirst() const { return (T*) m_sentinel.m_next; }
      inline T* GetLast() const { return (T*) m_sentinel.m_prev; }
      inline T* GetNext(const T* a_elem) const { return (T*) a_elem->gmListDoubleNode<T>::m_next; }
      inline T* GetPrev(const T* a_elem) const { return (T*) a_elem->gmListDoubleNode<T>::m_prev; }
      inline bool IsEmpty() const { return (m_sentinel.m_next == &m_sentinel); }
      inline Iterator First(void) const { return Iterator(static_cast<T*>(m_sentinel.m_next), this); }
      inline Iterator Last(void) const { return Iterator(static_cast<T*>(m_sentinel.m_prev), this); }
      
    private:
    
      gmListDoubleNode<T> m_sentinel;
    };

  13. #13
    Registered User
    Join Date
    Aug 2008
    Posts
    8
    Quote Originally Posted by matsp View Post
    I may have contributed to the confusion - the original poster is actually usign a metroworks compiler to compile the code - it compiles correctly on MS [as far as I can understand].

    --
    Mats
    Yeah that's right, no worries.

    Here's the gmListDoubleNode code if it's of any use:

    Code:
    /// \class gmListDoubleNode
    /// \brief intrusive node, must inherit this class templated to your class
    template <class T>
    class gmListDoubleNode
    {
    public:
    
      inline gmListDoubleNode() {}
    
      /// \brief Remove from list.  Allows node to unlink from unknown list.
      inline void RemoveAndNullify()
      {
        m_next->m_prev = m_prev;
        m_prev->m_next = m_next;
        this->Nullify();
      }
    
     
    private: 
      gmListDoubleNode * m_next;
      gmListDoubleNode * m_prev;
    
      friend class gmListDouble<T>;
    };

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by murdercityriot View Post
    I'm not using MSVC, I'm using the ISO compliant CodeWarrior compiler.
    Yeah sorry about that.

    I'm not sure what you mean about the type of a_elem.
    Your class is a template class, so I wanted to know what you instantiated the class with.
    You know, gmListDouble<?>.
    That would explain what the type of T is, since GetNext takes an argument of type const T*, so it would help.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    Aug 2008
    Posts
    8
    Quote Originally Posted by Elysia View Post
    That would explain what the type of T is, since GetNext takes an argument of type const T*, so it would help.
    The only place it's being called, as far as I can tell, is with the 'gmThread' type:

    Code:
    /// \class gmThread
    /// \brief gmThread.. try to keep this class's memory footprint small.. at the time of this comment, its
    ///        76 bytes.
    class gmThread : public gmListDoubleNode<gmThread>, public gmHashNode<int, gmThread>
    {

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dev-cpp - compiler options
    By tretton in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 06:20 PM
  2. Currency Conversion Program
    By kgraw21 in forum C Programming
    Replies: 5
    Last Post: 04-19-2002, 08:39 AM
  3. problem with output
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 08:34 PM
  4. Microsoft Visual C++ compiler, cast problem?
    By jonnie75 in forum C Programming
    Replies: 5
    Last Post: 11-10-2001, 08:53 AM
  5. Base conversion problem!
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-08-2001, 07:00 PM