Boost logo

Boost Users :

From: Daryle Walker (darylew_at_[hidden])
Date: 2005-12-06 01:40:45


On 12/5/05 11:28 PM, "Max Motovilov" <max_at_[hidden]> wrote:

[SNIP]
> Here's my sample snippet:
>
> try {
> wave_context::iterator_type p = ctx.begin(), last_known_good = p;
> bool done = false;
>
> while( !done ) {
> try {
> done = p == ctx.end();

There's a problem with the previous line. You can't dereference "p" if
you're at the end, but you don't prevent it.

> std::cout << p->get_value();
> ++p;
> last_known_good = p;
> } catch( boost::wave::preprocess_exception& err ) {
> if( err.get_severity() >= boost::wave::util::severity_error ) throw;
> complain( err );
> p = last_known_good;
> }
> }
> } catch( boost::wave::cpp_exception& err ) {
> complain( err );
> return false;
> }
[TRUNCATE]

Maybe your problems are caused by dereference violation. Try something
like:

//========================================================================
using namespace boost::wave;

try {
    typedef wave_context::iterator_type iterator;

    iterator last_known_good = ctx.begin();
    iterator const e = ctx.end();

    for ( iterator i = last_known_good ; e != i ; )
    {
        try {
            std::cout << i->get_value();
            last_known_good = ++i;
        } catch ( preprocess_exception & err ) {
            if ( err.get_severity() >= util::severity_error )
                throw;
            complain( err );
            i = last_known_good;
        }
    }
    //...
} catch ( cpp_exception & err ) {
    complain( err );
    return false;
}
//========================================================================

Looking at this, I still don't see how you avoid reading the problem context
element over and over....

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT hotmail DOT com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net