You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Jim Reitz <je...@home.com> on 2000/07/20 03:21:13 UTC

Why is inline keyword used on function declarations??

I've noticed some code in Xerces-C 1.20a that uses the inline keyword for
methods that are actually implemented in a .cpp file, as opposed to inside
an .hpp file.  I'm having some memory corruption problems with Borland's
CBuilder4.  The problem goes away when I disable inline function expansion
(-v- option), so I was just looking for clues as to why this was happening,
and I thought this odd use of the inline keyword might have something to do
with it.

For example, DOMStringImpl.hpp has the following code in the DOMStringData
class definition...

---from DOMStringImpl.hpp---
class   DOMStringData
{
public:
    unsigned int        fBufferLength;
    int                 fRefCount;
    XMLCh               fData[1];

    static DOMStringData *allocateBuffer(unsigned int length);
    inline void         addRef();    <--implemented in DOMString.cpp as
non-inline, why inline?
    inline void         removeRef(); <--implemented in DOMString.cpp as
non-inline, why inline?
};

---from DOMString.cpp---
void DOMStringData::removeRef()
{
    int result = XMLPlatformUtils::atomicDecrement(fRefCount);
    if (result==0)
    {
        fBufferLength = 0xcccc;
        fRefCount     = 0xcccc;
        delete [] this;  //  was allocated with new char[size] !
        XMLPlatformUtils::atomicDecrement(DOMString::gLiveStringDataCount);
    };
};

void DOMStringData::addRef()
{
    XMLPlatformUtils::atomicIncrement(fRefCount);
};

Why is inline used here?

thanks...

Jim Reitz
jereitz@home.com


Re: Why is inline keyword used on function declarations??

Posted by Dean Roddey <dr...@charmedquark.com>.
Those are just bugs. They were probably originally inlined, then got moved.
VC++ doesn't give any warning for this, and it sometimes a legitimate thing
to do. But, there probably aren't many, if any, legitmate uses of it in the
Xerces code base. So any that you find are probably bugs.

--------------------------
Dean Roddey
The CIDLib C++ Frameworks
Charmed Quark Software
droddey@charmedquark.com
http://www.charmedquark.com

"You young, and you gotcha health. Whatchoo wanna job fer?"


----- Original Message -----
From: "Jim Reitz" <je...@home.com>
To: <xe...@xml.apache.org>
Sent: Wednesday, July 19, 2000 6:21 PM
Subject: Why is inline keyword used on function declarations??


> I've noticed some code in Xerces-C 1.20a that uses the inline keyword for
> methods that are actually implemented in a .cpp file, as opposed to inside
> an .hpp file.  I'm having some memory corruption problems with Borland's
> CBuilder4.  The problem goes away when I disable inline function expansion
> (-v- option), so I was just looking for clues as to why this was
happening,
> and I thought this odd use of the inline keyword might have something to
do
> with it.
>
> For example, DOMStringImpl.hpp has the following code in the DOMStringData
> class definition...
>
> ---from DOMStringImpl.hpp---
> class   DOMStringData
> {
> public:
>     unsigned int        fBufferLength;
>     int                 fRefCount;
>     XMLCh               fData[1];
>
>     static DOMStringData *allocateBuffer(unsigned int length);
>     inline void         addRef();    <--implemented in DOMString.cpp as
> non-inline, why inline?
>     inline void         removeRef(); <--implemented in DOMString.cpp as
> non-inline, why inline?
> };
>
> ---from DOMString.cpp---
> void DOMStringData::removeRef()
> {
>     int result = XMLPlatformUtils::atomicDecrement(fRefCount);
>     if (result==0)
>     {
>         fBufferLength = 0xcccc;
>         fRefCount     = 0xcccc;
>         delete [] this;  //  was allocated with new char[size] !
>
XMLPlatformUtils::atomicDecrement(DOMString::gLiveStringDataCount);
>     };
> };
>
> void DOMStringData::addRef()
> {
>     XMLPlatformUtils::atomicIncrement(fRefCount);
> };
>
> Why is inline used here?
>
> thanks...
>
> Jim Reitz
> jereitz@home.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>