unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Why named structs and unions? C11 supports anonymous structs and unions
@ 2018-02-12  3:14 Daniel Colascione
  2018-02-12  3:56 ` Paul Eggert
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Colascione @ 2018-02-12  3:14 UTC (permalink / raw)
  To: Emacs developers

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?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why named structs and unions? C11 supports anonymous structs and unions
  2018-02-12  3:14 Why named structs and unions? C11 supports anonymous structs and unions Daniel Colascione
@ 2018-02-12  3:56 ` Paul Eggert
  2018-02-12  4:09   ` Daniel Colascione
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Eggert @ 2018-02-12  3:56 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: Emacs Development

Daniel Colascione wrote:

> Now we get all the alignment benefits of alignas, but without the ugly "u.s." stuff.

That assumes C11, though. Currently Emacs assumes only C99. Although Emacs can 
use C11 features when 'configure' determines them to work, I don't offhand see 
how this could be done for this particular feature without contorting the C code 
even more than it's contorted now.

> Instead of XCONS(c)->car, we now write XCONS(c)->u.s.car.

Normally in C code we write XCAR (c) instead of writing either form. The u.s. 
business is intended to be used only within a small set of source-code locations 
that need to know the internal structure of Lisp objects, and most C code 
shouldn't care whether it's '->car' or '->u.s.car'. Admittedly there are more 
occurrences of '->u.s.' than we'd like.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why named structs and unions? C11 supports anonymous structs and unions
  2018-02-12  3:56 ` Paul Eggert
@ 2018-02-12  4:09   ` Daniel Colascione
  2018-02-12  7:28     ` Paul Eggert
                       ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Daniel Colascione @ 2018-02-12  4:09 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Emacs Development

[-- Attachment #1: Type: text/html, Size: 2116 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why named structs and unions? C11 supports anonymous structs and unions
  2018-02-12  4:09   ` Daniel Colascione
@ 2018-02-12  7:28     ` Paul Eggert
  2018-02-12 20:22       ` Daniel Colascione
  2018-02-12 22:18     ` Richard Stallman
  2018-02-12 22:18     ` Richard Stallman
  2 siblings, 1 reply; 8+ messages in thread
From: Paul Eggert @ 2018-02-12  7:28 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: Emacs Development

Daniel Colascione wrote:
> I feel like being stuck on C99 and not being able to use C11 would be
> much rarer. Besides: C99 compilers usually supported anonymous structs and
> unions as an extension.

One counterexample is the vendor-supplied compiler on the main server of our 
department, which is running Solaris 5.10 (circa 2005). This compiler is Sun C 
5.9 (circa 2009). Although more recent versions of this compiler do support 
anonymous structs and unions, bug reports are still being filed about the 
feature, e.g., https://community.oracle.com/thread/4106986 dated December 2017. 
So I would say it's still a bit dicey in more-recent versions.

If it were really important to require this C11 feature I suppose we could forge 
ahead and do it and tell laggards to upgrade their compilers or use GCC. But my 
impression is that the feature is mostly just a nicety, at least for Emacs.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why named structs and unions? C11 supports anonymous structs and unions
  2018-02-12  7:28     ` Paul Eggert
@ 2018-02-12 20:22       ` Daniel Colascione
  2018-02-12 20:37         ` Paul Eggert
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Colascione @ 2018-02-12 20:22 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Emacs Development

On 02/11/2018 11:28 PM, Paul Eggert wrote:
> Daniel Colascione wrote:
>> I feel like being stuck on C99 and not being able to use C11 would be
>> much rarer. Besides: C99 compilers usually supported anonymous structs 
>> and
>> unions as an extension.
> 
> One counterexample is the vendor-supplied compiler on the main server of 
> our department, which is running Solaris 5.10 (circa 2005). This 
> compiler is Sun C 5.9 (circa 2009). Although more recent versions of 
> this compiler do support anonymous structs and unions, bug reports are 
> still being filed about the feature, e.g., 
> https://community.oracle.com/thread/4106986 dated December 2017. So I 
> would say it's still a bit dicey in more-recent versions.

That's unfortunate.

> If it were really important to require this C11 feature I suppose we 
> could forge ahead and do it and tell laggards to upgrade their compilers 
> or use GCC. But my impression is that the feature is mostly just a 
> nicety, at least for Emacs.

If there would be real people adversely impacted by a C11 requirement, 
we can hold off a little while. The union stuff is merely ugly; it's not 
a severe problem. I'd definitely like to move to C11 and anonymous inner 
structures eventually though.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why named structs and unions? C11 supports anonymous structs and unions
  2018-02-12 20:22       ` Daniel Colascione
@ 2018-02-12 20:37         ` Paul Eggert
  0 siblings, 0 replies; 8+ messages in thread
From: Paul Eggert @ 2018-02-12 20:37 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: Emacs Development

On 02/12/2018 12:22 PM, Daniel Colascione wrote:
> I'd definitely like to move to C11 and anonymous inner structures 
> eventually though.

Likewise. It's merely a matter of timing. Emacs didn't start assuming 
C99 until 15 years later, in 2014 (see Bug#17487). C11 is less of a lift 
than C99 was, so I think Emacs can start assuming C11 well before 2025, 
which would be the corresponding delay for the newer version.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why named structs and unions? C11 supports anonymous structs and unions
  2018-02-12  4:09   ` Daniel Colascione
  2018-02-12  7:28     ` Paul Eggert
@ 2018-02-12 22:18     ` Richard Stallman
  2018-02-12 22:18     ` Richard Stallman
  2 siblings, 0 replies; 8+ messages in thread
From: Richard Stallman @ 2018-02-12 22:18 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: eggert, Emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

It has not been long enough since 2011 to desupport
prior C compilers.  Let's wait another 3 years and see
what the situation is.

In the mean time, using accessor macros more often
would be equally clear and avoid imposing tool constraints.
-- 
Dr Richard Stallman
President, Free Software Foundation (https://gnu.org, https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)
Skype: No way! See https://stallman.org/skype.html.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Why named structs and unions? C11 supports anonymous structs and unions
  2018-02-12  4:09   ` Daniel Colascione
  2018-02-12  7:28     ` Paul Eggert
  2018-02-12 22:18     ` Richard Stallman
@ 2018-02-12 22:18     ` Richard Stallman
  2 siblings, 0 replies; 8+ messages in thread
From: Richard Stallman @ 2018-02-12 22:18 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: eggert, Emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > Now a++ generates
  > a temporary or rvalue i.e. you cannot assign a value to it like
  > (a++ = 7) and increment/decrement of temporaries is not
  > allowed, causing compilation to fail.

I added explanation of that.

  > > What is "temporary generation"?
  > >
  > > The term "rvalues" is not used.

We don't need to define or use those terms.


-- 
Dr Richard Stallman
President, Free Software Foundation (https://gnu.org, https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)
Skype: No way! See https://stallman.org/skype.html.




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-02-12 22:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-12  3:14 Why named structs and unions? C11 supports anonymous structs and unions Daniel Colascione
2018-02-12  3:56 ` Paul Eggert
2018-02-12  4:09   ` Daniel Colascione
2018-02-12  7:28     ` Paul Eggert
2018-02-12 20:22       ` Daniel Colascione
2018-02-12 20:37         ` Paul Eggert
2018-02-12 22:18     ` Richard Stallman
2018-02-12 22:18     ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).