|
Boost Users : |
Subject: Re: [Boost-users] [Spirit][Date_Time] Parsing of boost date_time (segfault)
From: AgustÃn K-ballo Bergé (kaballo86_at_[hidden])
Date: 2011-05-03 02:20:40
On 03/05/2011 2:55, Vitaly Budovski wrote:
> boost::uint16_t year;
> boost::uint8_t month;
> boost::uint8_t day;
>
> boost::uint8_t hour;
> boost::uint8_t minute;
> boost::uint8_t second;
>
> date =
> (
> big_word[ref(year) = _1]>> byte_[ref(month) = _1]>>
> byte_[ref(day) = _1]>> eps[_val =
> construct<boost::gregorian::date>(cref(year), cref(month),
> cref(day))]
> )
> ;
You are passing references to local objects. Whenever the actual parsing
happens, which it's not during grammar construction, the referred
objects do not longer exist.
You should declare those objects as class members, or even better use
Phoenix's locals; and I'm pretty sure that there is a way to do what you
want with no temporaries. The attribute of
big_word[ref(year) = _1]>> byte_[ref(month) = _1]>>
byte_[ref(day) = _1]
should be something like tuple< uint16_t, uint8_t, uint8_t >, which one
would be able to use to construct a gregorian date. I'm not fluent in
Spirit, so I hope one of the experts out there comes up with an example
on how to do this.
AgustÃn Bergé.-
http://talesofcpp.blogspot.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