Problems with a std::vector (begin and end): Different behavior debug and release version

Discussion in 'C++' started by Hans Stoessel, Apr 15, 2010.

  1. Windows XP / Visual Studio 2005
    -----------------------------------

    Hi

    This is a code piece from an automatic generated C++ file in gSOAP:

    SOAP_FMAC3 int SOAP_FMAC4 soap_out_std__vectorTemplateOfstd__string(struct
    soap *soap, const char *tag, int id, const std::vector<std::string >*a,
    const char *type)
    {
    for (std::vector<std::string >::const_iterator i = a->begin(); i !=
    a->end(); ++i)
    {
    if (soap_out_std__string(soap, tag, id, &(*i), ""))
    return soap->error;
    }
    return SOAP_OK;
    }

    I have a different behaviors in the debug and release version of the
    application! The vector contains one element.

    DEBUG:
    The for loop is called one time, as it should be.

    RELEASE:
    The for loop is NEVER called, because the iterator i is a->end().

    I have no idea why. I detect this with log files.

    Interesting is the follow: I tried to reproduce this behavior in my own
    code. The behavior in my code is correct, in the release and in the debug
    version.

    Any ideas?
    A comiler option?
    An include?

    Thanks for any hints.
    Hans
     
    Hans Stoessel, Apr 15, 2010
    #1
    1. Advertising

  2. Re: Problems with a std::vector (begin and end): Different behaviordebug and release version

    * Hans Stoessel:
    > Windows XP / Visual Studio 2005
    > -----------------------------------
    >
    > Hi
    >
    > This is a code piece from an automatic generated C++ file in gSOAP:
    >
    > SOAP_FMAC3 int SOAP_FMAC4 soap_out_std__vectorTemplateOfstd__string(struct
    > soap *soap, const char *tag, int id, const std::vector<std::string >*a,
    > const char *type)
    > {
    > for (std::vector<std::string >::const_iterator i = a->begin(); i !=
    > a->end(); ++i)
    > {
    > if (soap_out_std__string(soap, tag, id, &(*i), ""))
    > return soap->error;
    > }
    > return SOAP_OK;
    > }


    Arguments that aren't used, and passing by pointer instead of by reference,
    indicates less than brilliance on the part of the programmer who wrote the
    template for this generated code.


    > I have a different behaviors in the debug and release version of the
    > application! The vector contains one element.
    >
    > DEBUG:
    > The for loop is called one time, as it should be.
    >
    > RELEASE:
    > The for loop is NEVER called, because the iterator i is a->end().


    In that case the vector in the release version contains no elements.


    > I have no idea why.


    It's somewhere in the code you haven't shown. Most probably an assert with side
    effects, or something like that. Given the quality (novice level) of the
    generated code you've shown, it may be in some of Microsoft's code.

    Consider asking in a Microsoft-specific group.


    Cheers,

    - Alf
     
    Alf P. Steinbach, Apr 15, 2010
    #2
    1. Advertising

  3. > In that case the vector in the release version contains no elements.
    >
    >


    If I get out the size of the vector in a log file (release version), the
    size of the vector is 1.

    Hans
     
    Hans Stoessel, Apr 15, 2010
    #3
  4. Hans Stoessel

    tonydee Guest

    Re: Problems with a std::vector (begin and end): Different behaviordebug and release version

    On Apr 15, 5:18 pm, "Hans Stoessel" <>
    wrote:
    > > In that case the vector in the release version contains no elements.

    >
    > If I get out the size of the vector in a log file (release version), the
    > size of the vector is 1.


    When? Did you put the trace just inside that generated function,
    reporting the size and whether begin() == end()? If you really have
    both size == 1 when begin() == end(), that's violating vector's
    invariants, and probably indicates corruption due to memory
    mismanagement or similar issues. Keep simplifying the code until the
    bug goes away or you have a trivial but complete test case that
    fails....

    Cheers,
    Tony
     
    tonydee, Apr 15, 2010
    #4
  5. Hi

    I solved the error.

    I had the error in an InDesign plugin. I had to include the header
    "VCPluginHeaders.h", then it works.

    Thanks.

    Regards
    Hans



    "tonydee" <> schrieb im Newsbeitrag
    news:...
    On Apr 15, 5:18 pm, "Hans Stoessel" <>
    wrote:
    > > In that case the vector in the release version contains no elements.

    >
    > If I get out the size of the vector in a log file (release version), the
    > size of the vector is 1.


    When? Did you put the trace just inside that generated function,
    reporting the size and whether begin() == end()? If you really have
    both size == 1 when begin() == end(), that's violating vector's
    invariants, and probably indicates corruption due to memory
    mismanagement or similar issues. Keep simplifying the code until the
    bug goes away or you have a trivial but complete test case that
    fails....

    Cheers,
    Tony
     
    Hans Stoessel, Apr 22, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. croeltgen
    Replies:
    1
    Views:
    504
    Andrew Thompson
    Oct 25, 2004
  2. Replies:
    6
    Views:
    486
    Markus Grueneis
    Sep 10, 2006
  3. Replies:
    3
    Views:
    327
    Clark S. Cox III
    Sep 11, 2006
  4. shari
    Replies:
    3
    Views:
    396
    Mark Rae
    May 17, 2007
  5. Kurt M. Dresner

    do...end vs. begin..end

    Kurt M. Dresner, Jul 11, 2003, in forum: Ruby
    Replies:
    3
    Views:
    115
Loading...

Share This Page