Bug methinks :-)

Joe Armstrong joe@REDACTED
Tue Apr 9 10:25:09 CEST 2002


If I define a couple of macros

-define(Entry(X, Y), (Y:X)).

-define(DWORD, 32/unsigned-little-integer).
-define(LONG, 32/unsigned-little-integer).
-define(WORD, 16/unsigned-little-integer).
-define(BYTE, 8/unsigned-little-integer).

Then some fancy stuff in C

Like 

  typedef struct IMAGE_OPTIONAL_HEADER {
     DWORD   ImageBase;
     DWORD   SectionAlignment;
     DWORD   FileAlignment;
     WORD    MajorOperatingSystemVersion;

Becomes in Erlang

 <<  ?Entry(?DWORD, ImageBase),  
     ?Entry(?DWORD, SectionAlignment),
     ?Entry(?DWORD, FileAlignment),
     ?Entry(?WORD, MajorOperatingSystemVersion),

Which is near enough to make me feel warm and fuzzy inside.

If I then compile this I get an error.

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.

Compiling gives

	> erlc bug.erl
	bug.erl:14: illegal pattern
	bug.erl:15: illegal pattern
	bug.erl:16: illegal pattern
	bug.erl:17: illegal pattern

But amazingly

	> erlc -P bug.erl
        > mv bug.P bug1.erl
        > erlc bug1.erl

Compiles correctly - which is not what I had expected.

/Joe





More information about the erlang-questions mailing list