
On Tuesday, May 03, 2011 07:55:39 AM Vitaly Budovski wrote:
Hi,
I had a go at building a binary parser to output a date/time object. Unfortunately, I ran into some serious issues. One of my grammars causes the application to segfault when compiled with gcc, but not in clang. I'm not sure if this is a bug in gcc, boost, or simply a programming error. Please see attached file. Is there a better way to achieve what I need (final output should be ptime object)? All suggestions welcome :)
It's a programming error: The variables year, month, day, hour, minute and second are only defined in the constructor. You capture them by reference in the semantic actions. The actual parsing does not happen in the construct, thus those ctor local variables are invalid. One solution would be to use rule local variables, for example: qi::rule< Iterator , boost::gregorian::date() , qi::locals< uint16_t // year, refer to as _a , uint8_t // month, refer to as _b , uint8_t // day, refer to as c >
date;
date = (big_word[_a = _1] >> byte[_b = _1] >> byte[_c = _1]) [_val = constructboost::posix_time::time_duration(_a, _b, _c)] See attached file for a full working solution with locals.
Thanks,
Vitaly