GNU bug report logs -
#61481
CC Mode 5.35.2 (C/*l); _Generic unsupported
Previous Next
Reported by: Po Lu <luangruo <at> yahoo.com>
Date: Mon, 13 Feb 2023 15:29:01 UTC
Severity: normal
Done: Alan Mackenzie <acm <at> muc.de>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
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!
[ .... ]
--
Alan Mackenzie (Nuremberg, Germany).
[diff.20230216.diff (text/plain, attachment)]
This bug report was last modified 2 years and 191 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.