Thread: Microsoft -> ISO conversion problem

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Terrific, so what does gmThread look like?
    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.

  2. #17
    Registered User
    Join Date
    Aug 2008
    Posts
    8
    Quote Originally Posted by Elysia View Post
    Terrific, so what does gmThread look like?
    Wasn't sure whether you'd want it all pasted! Here it is:

    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>
    {
    public:
      gmThread(gmMachine * a_machine, int a_initialByteSize = GMTHREAD_INITIALBYTESIZE);
      virtual ~gmThread();
    
      enum State
      {
        RUNNING = 0,
        SLEEPING,
        BLOCKED,
        KILLED,
    
        EXCEPTION, //!< exception state, for debugging
    
        SYS_PENDING,
        SYS_YIELD, 
        SYS_EXCEPTION,
      };
    
      inline const int GetKey() const { return m_id; }
    
    #if GM_USE_INCGC
      void GCScanRoots(gmMachine* a_machine, gmGarbageCollector* a_gc);
    #else //GM_USE_INCGC
      /// \brief Mark() will call Mark() for all objects in the stack.
      void Mark(gmuint32 a_mark);
    #endif //GM_USE_INCGC
    
      /// \brief Sys_Execute() will perform execution on this thread.  a this, function references, params and stack
      ///        frame must be pushed before a call to execute will succeed.
      /// \param a_return will be set to the return variable iff Sys_Execute returns gmThread::KILLED. 
      /// \return the new thread state.
      State Sys_Execute(gmVariable * a_return = NULL);
    
      /// \brief Sys_Reset() will reset the thread.
      void Sys_Reset(int a_id);
    
      /// \brief Sys_SetState() will set the thread state.
      inline void Sys_SetState(State a_state) { m_state = a_state; }
    
      /// \brief PushStackFrame will push a stack frame and adjust the instruction and code pointers. 
      ///        If the function to be called is a c bound function, the call will occur within PushStackFrame.
      ///        Before PushStackFrame is called, this, fp, and params must be pushed on the stack.
      /// \param a_numParameters is the number of params pushed after the function ref.
      /// \param a_ip is the current instruction pointer (pointing to instruction after call.) will be adjusted for new function.
      /// \param a_cp is the current code pointer.  will be adjusted for the new function. a_cp MUST be valid if a_ip is valid.
      /// \return gmThreadState
      State PushStackFrame(int a_numParameters, const gmuint8 ** a_ip = NULL, const gmuint8 ** a_cp = NULL);
    
    .
    .
    .
    etc.

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    This, with changes in red, compiles with gcc 3.4.2 with "g++ -Wall -pedantic -ansi -c xx.cpp"
    With an embedded compiler, I get a problem because Nullify() for gmListDoubleNode<T> doesn't have a member function Nullify(). Probably declared in the "GM_INCLUDE_ITERATOR(T)" part, which I don't have.

    Code:
    #define NULL 0
    
    template <class T>
    class gmListDoubleNode;
    
    /// \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:
    
      class gmListDoubleNode<T> m_sentinel;
    };
    
    
    /// \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>;
    };
    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.

  4. #19
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    What happens if you remove the <T> and change :: to ->?
    Code:
    inline T* GetNext(const T* a_elem) const { return (T*) a_elem->gmListDoubleNode->m_next; }

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