bug#61481: CC Mode 5.35.2 (C/*l); _Generic unsupported

Po Lu via CC-Mode-help <[email protected]> Fri, 17 Feb 2023 10:33:45 +0800
Newsgroups gmane.emacs.cc-mode.general
Message-ID <[email protected]>
Alan Mackenzie <[email protected]> writes:

> Hello, Po.
>
> On Mon, Feb 13, 2023 at 23:25:43 +0800, Po Lu via CC-Mode-help wrote:
>> Package: cc-mode
>
>> 2011 Standard C has a feature that works like `switch', except on the
>> type of an expression and with different syntax.
>
> Yuck!  How on Earth did something like this get included in the
> standard?  It's not used often (I wasn't aware of it until three days
> ago), it's wholly unlike anything else in C, and just takes up effort
> from compiler and editor maintainers.
>
>> Today, I had to figure out how to port some code written with that in
>> mind to ANSI C, and surprisingly enough, found that CC Mode does not
>> support that feature at all.
>
> :-)
>
>> Code making use of _Generic looks more or less like this:
>
>> {
>>   const char *typename = _Generic ((expr),
>> 				   const char *:
>> 				     "const char *",
>> 				   int:
>> 				     "int",
>> 				   unsigned long:
>> 				     "unsigned long"
>> 				   default:
>> 				     NULL);
>> }
>
>> where `typename' is set to an appropriate value based on the type of the
>> expression ``expr''.
>
>> CC Mode already works remarkably well, but it should be taught to indent
>> the cases separately from the values.
>
> Thanks!
>
> I've made a first patch for this, which is fairly crude.  It handles
> only the indentation, not the fontification, which will be more
> difficult.
>
> Would you please try out the attached patch, and let me know how well it
> does the job.  Thanks!
>
> [ .... ]

Thanks, Alan.

I finished working on that code by now, so I have nothing to test it on.
If it works for you, please install, thanks.