public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [C2x] Disallow function attributes after function identifier
@ 2022-06-10 20:40 Alejandro Colomar
  2022-06-10 21:09 ` Joseph Myers
  2022-06-10 21:16 ` Jakub Jelinek
  0 siblings, 2 replies; 11+ messages in thread
From: Alejandro Colomar @ 2022-06-10 20:40 UTC (permalink / raw)
  To: Joseph Myers; +Cc: gcc


[-- Attachment #1.1: Type: text/plain, Size: 2186 bytes --]

Hi, Joseph!

I'd like to suggest a change in C2x regarding attributes.

Right now, the draft allows function attributes to go right at the 
beginning of a function prototype, or just before the opening parenthesis:

[[attr]] type f(params);
type f [[attr]](params);

I'd argue against the second one, for the following reasons:

C programmers are used to the "f(...)" notation so much that it would be 
a bit confusing to change that.

See for example a linux-man@ discussion: 
<https://lore.kernel.org/linux-man/d015464c-714d-771e-6829-c1032efab15d@cs.ucla.edu/T/#u>.

Not only that, but it's common practise to hide attributes in macros, as in:

#if __STDC_VERSION__ > 201710L
#define my_inline [[gnu::always_inline]]
#else
#define my_inline __attribute__((__always_inline__))
#endif

Now see a valid C2x function prototype:

my_inline type f(params);
type f my_inline(params);

I hope no-one will ever write that code, even if ISO C ever allows it, 
but I'd rather see ISO C to forbid that aberration.

And, as much as that becomes human unreadable, it also makes it 
impossible for simple utils to parse C code.

I'm writing a PCRE-based tool that finds declarations and definitions 
within source code repositories.  It's already quite good, if we take 
into account it's simplicity.  Since it doesn't involve anything close 
to a compiler, it can only make a best guess, based on the assumption 
that the code follows some sane coding style.  For example, the PCRE 
regex for finding a function prototype is

 
'(?s)^[\w[]([\w\s\(,\)[\]*]|::)+[\w\s\)*\]]\s+\**'"$1"'\s*\(([\w\s\(,\)[\]*]|::)+?(\.\.\.)?\)([\w\s\(,\)[\]]|::)*;'

See the whole program (sh(1) script): 
<http://www.alejandro-colomar.es/src/alx/alx/grepc.git/>

That would be completely broken if anything could go after the function 
identifier.

So, could you please drop that from C2x?


Cheers,

Alex


P.S.: The latest draft that I know of is N2731.  I guess there are newer 
ones.  Could you please name the latest one?

-- 
Alejandro Colomar
Linux man-pages comaintainer; http://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2022-06-13 15:54 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-10 20:40 [C2x] Disallow function attributes after function identifier Alejandro Colomar
2022-06-10 21:09 ` Joseph Myers
2022-06-10 21:35   ` Alejandro Colomar
2022-06-10 21:16 ` Jakub Jelinek
2022-06-10 21:31   ` Alejandro Colomar
2022-06-10 22:47     ` Jonathan Wakely
2022-06-11  9:03       ` Alejandro Colomar
2022-06-11 12:08         ` Gabriel Ravier
2022-06-11 20:20           ` Alejandro Colomar
2022-06-13 15:54             ` Jonathan Wakely
2022-06-11 12:53         ` Jonathan Wakely

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).