On 18 January 2016 at 17:45, Eric Blake <ebl...@redhat.com> wrote: > On 01/17/2016 04:45 PM, Programmingkid wrote: >>> What's the definition of the CMSG_SPACE macro under OS X? >>> >>> Paolo >> >> #define CMSG_SPACE(l) (__DARWIN_ALIGN32(sizeof(struct >> cmsghdr)) + __DARWIN_ALIGN32(l)) > > And the definition of __DARWIN_ALIGN32()? > > It looks like the definition is not properly resulting in a compile-time > constant, and therefore the warning about the initializer is resulting > because you can't initialize a dynamically-sized array. But you still > haven't shown us why the headers are resulting in a non-constant size.
FWIW, on my OSX system (OSX 10.10.5, Xcode 7.1), compiling the test program with gcc -Wall -E -o /tmp/varray.S /tmp/varray.c shows that the array definition expands to char control[(((__darwin_size_t)((char *)(__darwin_size_t)(sizeof(struct cmsghdr)) + (sizeof(__uint32_t) - 1)) &~ (sizeof(__uint32_t) - 1)) + ((__darwin_size_t)((char *)(__darwin_size_t)(sizeof(int) * 16) + (sizeof(__uint32_t) - 1)) &~ (sizeof(__uint32_t) - 1)))] = { 0 }; the relevant macro definitions being #define __DARWIN_ALIGNBYTES (sizeof(__darwin_size_t) - 1) #define __DARWIN_ALIGN32(p) ((__darwin_size_t)((char *)(__darwin_size_t)(p) + __DARWIN_ALIGNBYTES32) &~ __DARWIN_ALIGNBYTES32) this is with a 'gcc' that gcc --version reports as Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 7.0.0 (clang-700.1.76) Target: x86_64-apple-darwin14.5.0 Thread model: posix and which claims itself to be 4.2.1 by the printout from the test program (ie it's clang under the hood). I don't get any compiler warnings from gcc -Wall -O2 -o /tmp/varray /tmp/varray.c I don't know what the difference between my setup and John's is (likely an older clang version). thanks -- PMM