lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


[please forgive me if this isn't the appropriate place to discuss
Roberto's struct library]

Compiling struct in Windows works, accepting warnings about size_t ->
int conversions, which I normally ignore, but...

Running the provided test file in Windows 7 64bit, it fails here:

`assert(lib.pack('<T', -10) == string.char(256-10) .. string.char(255):rep(x))`

given the following minimal example:

```lua

local lib = require"struct"

x = lib.size("T") - 1

assert(lib.pack('<!T', 10) == string.char(10) .. string.char(0):rep(x))
assert(lib.pack('>!T', 10) == string.char(0):rep(x) .. string.char(10))

local str = lib.pack('<!T', -10)
local str2 = string.char(256-10)..string.char(255):rep(x)

print(x, #str, #str2)

for i = 1, #str do
  print(i, str:sub(i,i) == str2:sub(i,i),
    str:byte(i), str2:byte(i)
  )
end

assert(lib.pack('<T', -10) == string.char(256-10) .. string.char(255):rep(x))

```

Output in WIN64 is:

```
7       8       8
1       true    246     246
2       true    255     255
3       true    255     255
4       true    255     255
5       false   0       255
6       false   0       255
7       false   0       255
8       false   0       255
lua: aas_test.lua:19: assertion failed!
stack traceback:
        [C]: in function 'assert'
        aas_test.lua:19: in main chunk
        [C]: in ?
```

Output in OS X is:

```
7 8 8
1 true 246 246
2 true 255 255
3 true 255 255
4 true 255 255
5 true 255 255
6 true 255 255
7 true 255 255
8 true 255 255

```

...which is what one would hope for.

It appears as though the "other" half of the bits aren't getting masked.

Perhaps this behavior should be considered "undefined", given that
size_t is unsigned?

Does this point to a fundamental problem with using struct on 64bit
Windows, or to an edge case that I should be aware of, but not fearful
of?


-Andrew