Re: ffi.copy/ffi.string fails with volatile-qualified char array

  • From: Justin Cormack <justin@xxxxxxxxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 4 Nov 2013 12:54:26 +0000

On 4 Nov 2013 12:49, "Mike Pall" <mike-1311@xxxxxxxxxx> wrote:
>
> Philipp Kutin wrote:
> > > av = ffi.new "volatile char [12]"
> > > aa = ffi.new "char [12]"
> > > ffi.copy(aa, av, 1)
> > stdin:1: bad argument #2 to 'copy' (cannot convert 'volatile char
> > [12]' to 'const void *')
>
> This is in line with C semantics:
>
>   #include <string.h>
>
>   void foo(char *a, volatile char *b)
>   {
>     memcpy(a, b, 4);
>   }
>
> $ gcc -c test.c
> test.c: In function 'foo':
> test.c:5:3: warning: passing argument 2 of 'memcpy' discards 'volatile'
qualifier from pointer target type [enabled by default]
> In file included from test.c:1:0:
> /usr/include/string.h:42:14: note: expected 'const void * __restrict__'
but argument is of type 'volatile char *'
>
> Ok, so GCC treats it as a warning and the FFI treats it as an
> error. But implicit removal of qualifiers violates C semantics.
>

Does LuaJIT respect volatile semantics in terms of (not) optimising it?

Other related posts: