Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: struct tag (*[5])(float) Date: Thu, 02 Apr 2015 15:18:52 -0700 Organization: None to speak of Lines: 63 Message-ID: <87ego2gomr.fsf@kst-u.example.com> References: <551C65E3.8010903@verizon.net> <87bnj7i5nn.fsf@kst-u.example.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="9be37d943435275679235b07c7947eef"; logging-data="27836"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18kQSwZ5J2D2ONF7m3BC+lw" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:R+uDMVow78ZNi3XHzzaHhp9wgSg= sha1:yDWnEnKqwSWKzXjYUpdrKDg9Z+I= Xref: csiph.com comp.lang.c:59494 Bartc writes: > On 02/04/2015 04:13, Keith Thompson wrote: >> Bartc writes: [...] >>> I could try and tell you what the above means, but it will a >>> guess. Although I know the name goes just before the "*", because I >>> tested my guess with a compiler. >> >> No, it goes after the identifier. (And I don't think I can explain how >> I figured that out.) > > You mean, after the "*"...? Yes. >> I agree with you that C's declaration syntax is unnecessarily obscure, >> and I occasionally resort to cdecl myself. > > Maybe it should be part of the language allowing you to optionally use > English to declare types: > > _cdeclare("name as array 5 of pointer to function (float) returning > struct tag") ; > > The compiler sees this as: > > struct tag (*name[5])(float) ; I dislike that idea, at least as a language feature. We'd have to define *rigorously* an English-like syntax for declarations, and it would have to coexist with the existing syntax in the same language. But I can see the convenience. You could instead have a tool that translates an English-like syntax into valid C declarations. You could then use that tool as part of your build process, to construct C source files that you then compile. It could retain the "English" version as a comment. For example, it could take as input: @ name as array 5 of pointer to function (float) returning struct tag and produce as output: /* @ name as array 5 of pointer to function (float) returning struct tag */ struct tag (*name[5])(float); Personally I'd prefer to run the tool manually and include the generated declarations in the C source file, which is then what's maintained. The automatically generated comments would still be useful. Any non-C syntax for declarations is going to annoy experienced C programmers -- much like the old #define BEGIN { #define END } stuff. [...] -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"