[ragel-users] Newbie problem with reading unsigned numbers

Adrian Thurston adrian.thurston at esentire.com
Wed Sep 2 17:17:04 UTC 2009


The problem is casting. The fc expression is signed char (since the 
default alphabet is char) and it is being upcast to int size. In the 
process the high bits become 1 to preserve the negative property of the 
value.

Use:

alphtype unsigned char;

And make p and pe unsigned char* type;

-Adrian

Neil Webster wrote:
> Hi Guys,
> 
> Please accept my apologies for the email clutter but I forgot the 
> attachment ....
> 
> On Wed, 2009-09-02 at 13:08 -0400, Neil Webster wrote:
>> I am trying to create a reusable structure for reading in data from a
>> binary data stream. I have attached a ragel file that demonstrates the
>> problem I am having and would appreciate tips and advice on what I am
>> doing wrong or better ways to go about solving the problem.
>>
>> I have defined Word8b, Word16b and Word32b to represent the blocks I
>> will be reading from the data stream. The data is accumulated into a
>> temporary variable (temp) and then assigned to the specific variable on
>> exit from the appropriate machine. It works fine for small numbers but
>> does strange things with numbers >127. It seems to be a problem with
>> signed vs unsigned but I can't figure out what it is.
>>
>> What I expect
>> a8 1 b8 ff a16 2 b16 fe a32 3 b32 fd
>>
>> What I get
>>  
>> a8 1 b8 ffff a16 2 b16 fffe a32 3 b32 fffffffd 
>>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> ragel-users mailing list
> ragel-users at complang.org
> http://www.complang.org/mailman/listinfo/ragel-users




More information about the ragel-users mailing list