Bug methinks :-)

Robert Virding robert.virding@REDACTED
Tue Apr 16 08:46:42 CEST 2002


Joe Armstrong wrote:
> Here's bug.erl
> 
> -module(bug).
> 
> -compile(export_all). 
> 
> -define(Entry(X, Y), (Y:X)).
> 
> -define(DWORD, 32/unsigned-little-integer).
> -define(WORD, 16/unsigned-little-integer).
> 
> foo(B) ->
>     <<?Entry(?DWORD, ImageBase),
>      ?Entry(?DWORD, SectionAlignment),
>      ?Entry(?DWORD, FileAlignment),
>      ?Entry(?WORD, MajorOperatingSystemVersion)>> = B.

You are actually hitting two different things here:

1. Seeing you have put parantheses around the bit expression it is 
parsed as an expression not as a bit expression with extra optional fields.

2. A mis-feature in the parser which allows to get past parsing and be 
caught in the linter.

So if you expand your macros (look in bug.P) you will see:

(ImageBase:32/unsigned-little-integer)

and : / - are parsed as normal operators.  Without the paratheses is is 
parsed as you expect.  That : is parsed as an operator is the mis-feature.

So this is not a bug, and there is no real way around it as we need to 
be able to have paranthesised expressions in bit expressions.  Otherwise 
the syntax would be extremely restricted, basically just variables which 
would really suck.

I will however fix up the : as operator bug!.

Robert




More information about the erlang-questions mailing list