Hi Nicholas,
I don't think that variable size array inside a union is allowed by C99. I
don't have a copy of the standard but N1256 says:
(in 6.7.2.1 Structure and union specifiers)
"A member of a structure or union may have any object type other than a
variably modified type."
"variably modified type" is defined in 6.7.5 Declarators:
"A full declarator is a declarator that is not part of another declarator. The
end of a full declarator is
a sequence point. If, in the nested sequence of declarators in a full
declarator, there is a declarator
specifying a variable length array type, the type specified by the full
declarator is said to be variably
modified. Furthermore, any type derived by declarator type derivation from a
variably modified type
is itself variably modified."
I did a quick test using online Comeau C99 compiler and it reports an error:
int main(int argc, char* argv[])
{
union {int a; char b[argc]; } u;
}
"ComeauTest.c", line 3: error: expression must have a constant value
union {int a; char b[argc]; } u;
^
"ComeauTest.c", line 3: warning: variable "u" was declared but never referenced
union {int a; char b[argc]; } u;
^
1 error detected in the compilation of "ComeauTest.c".
Alex
23.02.10, 00:11, "Nicholas Marriott" <[email protected]>:
> Hi
>
> Did you try building with -std=c99?
>
>
> On Mon, Feb 22, 2010 at 11:39:44PM +0000, Alexander Nasonov wrote:
> > After being subscribed to this list for a while, the list is
> > apparently alive. Seems like my message was sent at the worng time.
> >
> > Nikolas,
> > What's your view on using a buffer with a size known only at runtime?
> >
> > Thanks,
> > Alex
> >
> > Alexander Nasonov wrote:
> > > Hi,
> > >
> > > CMSG_SPACE(sizeof(int)) does not return a constant on NetBSD.
> > > If you compile tmux with the Intel C++ compiler 11.1, the program
> > > will crash in msgbuf_write because the compiler can't deduce a size
> > > of buf and sets it to 0:
> > >
> > > union {
> > > struct cmsghdr hdr;
> > > char buf[CMSG_SPACE(sizeof(int))];
> > > } cmsgbuf;
> > >
> > > and the result of sizeof(buf) is 0. This leads to a crash.
> > >
> > > Any chance to get this fixed in the next version?
> > >
> > > Thanks,
> > > Alex
> > >
> > > PS see this commit message in NetBSD repository for more information
> about CMSG_SPACE:
> > >
> > >
> http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/sys/socket.h?only_with_tag=MAIN#rev1.51
> > >
> > > Revision 1.51 / (download) - annotate - [select for diffs], Thu Mar 2
> 07:41:50 2000 UTC (9 years, 8 months ago) by itojun
> > > Branch: MAIN
> > > Changes since 1.50: +10 -4 lines
> > > Diff to previous 1.50 (colored)
> > >
> > > make CMSG_ALIGN always synchronize with kernel's idea of ALIGNBYTES.
> > > ancillary data alignment will be ALIGNBYTES, not sizeof(long) - 1, from
> now.
> > >
> > > CMSG_xx will NOT resolve into constant. if you use CMSG_xx to allocate
> > > arrays, you'll lose.
> > >
> > > bump shlib minor for libc.
> > >
> > > NOTE: if you are on top of arch with ALIGNBYTES != sizeof(long) - 1,
> > > you need to recompile IPv6-related binaries. there is no way to
> guarantee
> > > backward compat in this aspect. sorry for this. this should be the last
> > > backward compat breakage for IPv6-related ancillary data manipulation.
> > > (we still have PR 9516 for unix-domain sockets...)
> > >
> > >
> ------------------------------------------------------------------------------
> > > Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> > > trial. Simplify your report design, integration and deployment - and
> focus on
> > > what you do best, core application coding. Discover what's new with
> > > Crystal Reports now. http://p.sf.net/sfu/bobj-july
> > > _______________________________________________
> > > tmux-users mailing list
> > > [email protected]
> > > https://lists.sourceforge.net/lists/listinfo/tmux-users
> >
> >
> >
> ------------------------------------------------------------------------------
> > Download IntelĀ® Parallel Studio Eval
> > Try the new software tools for yourself. Speed compiling, find bugs
> > proactively, and fine-tune applications for parallel performance.
> > See why Intel Parallel Studio got high marks during beta.
> > http://p.sf.net/sfu/intel-sw-dev
> > _______________________________________________
> > tmux-users mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/tmux-users
>
>
--
Alexander Nasonov
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
tmux-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-users