From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.devel Subject: Why named structs and unions? C11 supports anonymous structs and unions Date: Sun, 11 Feb 2018 19:14:59 -0800 Message-ID: <53a9ab33-cdd5-99b3-aeef-f52776a5bf8d@dancol.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1518405238 6063 195.159.176.226 (12 Feb 2018 03:13:58 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 12 Feb 2018 03:13:58 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 12 04:13:54 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1el4Yw-000157-5S for ged-emacs-devel@m.gmane.org; Mon, 12 Feb 2018 04:13:50 +0100 Original-Received: from localhost ([::1]:60106 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1el4ax-0004Y4-OB for ged-emacs-devel@m.gmane.org; Sun, 11 Feb 2018 22:15:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1el4aJ-0004V9-QC for emacs-devel@gnu.org; Sun, 11 Feb 2018 22:15:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1el4aI-0006xF-Ss for emacs-devel@gnu.org; Sun, 11 Feb 2018 22:15:15 -0500 Original-Received: from dancol.org ([2600:3c01::f03c:91ff:fedf:adf3]:60884) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1el4aI-0006nm-JZ for emacs-devel@gnu.org; Sun, 11 Feb 2018 22:15:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=dancol.org; s=x; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Date:Message-ID:Subject:From:To; bh=zdlg4Nj81ZWA4rTMFVIqf0rD3SZX5p3hAYUGzUpU8E8=; b=mBHxc39qkR6Ow10pSvm8+4RYjzRHfdwyGBoeZtYrWH6KhxUujX70mzLRrlZZg8GxxFUcf/JzsBAQQxNwdspaDUtvTNUdPxCNF7cMUkVWItEAgkCK9R+Zf625IP+YcZlHrhw1gE+3SxiRPjiWvdQy/CmHl/J9tj95eF0o44Sm3HnEnYbjSs33XMsRvIjRfx8bUwjXtn8e8yYyKPZK0W7C3GGNONo2QX549+kJNFQXawc5mvlMjgxxn95kdJi0j1Ra2v+2w3eYZxB2BZXe+FFZeqZlsAUwUl3xZyUcUk6x5hTpIXHyvsLEDlBd6HiwjrZke2BaPtYZ/o5+wRQASip55A==; Original-Received: from [2604:4080:1321:8ab0:44a9:f170:2cad:5d14] by dancol.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1el4aA-0000hB-Pk for emacs-devel@gnu.org; Sun, 11 Feb 2018 19:15:06 -0800 Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2600:3c01::f03c:91ff:fedf:adf3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:222673 Archived-At: Recently, we changed structs from being declared plainly to being structs-of-a-union-containing-a-struct-and-a-dummy-aligner. I understand the reasoning for this change, but not the way it's done. It's uglified the code. Instead of XCONS(c)->car, we now write XCONS(c)->u.s.car. We don't have to though. Instead of: struct foo { union { struct { int stuff1; int stuff2; } s; char alignas(GCALIGNMENT) gcaligned; } u; }; we can write this: struct foo { union { struct { int stuff1; int stuff2; }; char alignas(GCALIGNMENT) gcaligned; }; }; Now we get all the alignment benefits of alignas, but without the ugly "u.s." stuff. C11 allows these anonymous composite members, and AFAICT, so does every compiler that anyone cares about anymore. So why not use them?