Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail From: ootiib@hot.ee Newsgroups: comp.std.c++ Subject: Re: proposal: new bitfield value to ensure structure packing Date: Mon, 25 Nov 2013 08:44:23 -0800 (PST) Organization: unknown Lines: 49 Sender: std-cpp-request@vandevoorde.com Approved: stephen.clamage@oracle.com Message-ID: References: NNTP-Posting-Host: +JkpZibMwIi5nVOHXQ3oOY/kicGCGbuUAWe7mcLDk64= Content-Type: text/plain; charset=ISO-8859-1 X-Trace: news.albasani.net UxcuSDw7PRBZ/1RPzg4NtROP4S3JszgGeW+a/O0LQFKhVyX/zGcEL577Is9sw2UMA0N7pwOHji4tqVcWuQaRnw== X-Complaints-To: abuse@albasani.net NNTP-Posting-Date: Mon, 25 Nov 2013 16:44:26 +0000 (UTC) X-Mailer: Perl5 Mail::Internet v2.05 X-Submission-Address: std-cpp-submit@vandevoorde.com Cancel-Lock: sha1:HhyXk8oWowofJVdjSWGZItEGoek= X-Original-Date: Sun, 24 Nov 2013 03:53:36 -0800 (PST) Xref: csiph.com comp.std.c++:694 On Friday, 22 November 2013 17:04:33 UTC+2, daniel...@googlemail.com wrote: > My prosal is to enable specifying a bit field length of -1 to tell the > compiler that in such position it should not insert spaces, or in other > words, that the previous and next members should be adjacent in memory. > With this syntax, the FogFrame would end as: > > struct FogFrame > { > FogFrameHeader header; > uint8_t: -1; // No spaces here > uint8_t dummy; > uint8_t: -1; // Ditto > int32_t data :22; > int32_t :10; > }; Do I understand you correctly that it overrules alignment requirements? So for example: struct A { char c; int i; }; On most current desktops 'A::c' is 1 byte, 'A::i' is 4 bytes and there is 3-byte padding between them so 'A' is 8 bytes long. Now you want to have: struct A { char c; int:-1; int i; }; That removes the above described 3-byte padding? It can be implemented but the syntax to achieve it looks unfortunate and also the 'A::i' stops being 'int' in sense one can't take reference or pointer to it and also it may be split between different cache pages that normal 'int' never is. If you want to remove alignment requirements of 'A::i' then why not simply: struct A { char c; int i:-1; }; ? -- [ comp.std.c++ is moderated. To submit articles, try posting with your ] [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]