Obtain pointer from static array literal

codic codic at linuxmail.org
Fri Oct 8 02:49:17 UTC 2021

I am working with a C API (XCB) which uses `void*` a lot to 
obtain parameter packs; these are very small and throwaway so I 
want them to be allocated to the stack.

Of course, this is valid, but a bit painful:
uint[4] params=[x,y,width,height];
especially when you have lots of calls. now, this compiles:
// (import std.array)
but is it well-formed? or is it UB because it is a rvalue and 
scope ends?
i.e. here is an example program, is it well formed?
import core.stdc.stdio, std.array;

void thing(int* abc) {
   printf("%d\n", *abc);

extern(C) void main() {
At any rate, it runs fine consistently with ldc:
$ ldc2 test.d -fsanitize=address
$ ./test

I don't know if it is spec-compliant though, or if it is actually 
causing UB here and I don't notice it.

More information about the Digitalmars-d-learn mailing list