Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.compilers > #3262
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.compilers |
| Subject | Re: C types, was What attributes of a programming language simplify its use? |
| Date | 2022-12-09 13:21 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <22-12-015@comp.compilers> (permalink) |
| References | (2 earlier) <22-12-004@comp.compilers> <22-12-007@comp.compilers> <22-12-010@comp.compilers> <22-12-011@comp.compilers> <22-12-012@comp.compilers> |
On 08/12/2022 21:42, Hans-Peter Diettrich wrote: > On 12/8/22 2:53 AM, Keith Thompson wrote: >> Hans-Peter Diettrich <DrDiettrich1@netscape.net> writes: >>> On 12/6/22 6:56 PM, Keith Thompson wrote: >> [...] >>>> "int int" is a syntax error. >>> >>> I could not find in the (older) C++ grammar why "int int" should be a >>> *syntax* error. Aren't both "int" and "long" simple-type-specifier's >>> which can occur multiple times in a decl-specifier-seq? >> >> No, there are specific rules that specify the way they can be used. >> In the 2011 ISO C standard standard (I use the draft from >> https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf), the valid >> type specifiers are listed in section 6.7.2. > > Thanks for the link :-) > >> At least one type specifier shall be given in the declaration >> specifiers in each declaration, and in the specifier-qualifier >> list in each struct declaration and type name. Each list of type >> specifiers shall be one of the following multisets (delimited >> by commas, when there is more than one multiset per item); >> the type specifiers may occur in any order, possibly intermixed >> with the other declaration specifiers. > > So let me repeat my questions: > > - Why is "int int" a syntax error? "At least one..." allows for more > than one type-specifier in declaration-specifiers (6.7). > > - What's "long int long"? My current (Arduino) C++ compiler doesn't flag > it as an error. To my reading of the C standard (I'm looking at C11 at the moment, the same version as Keith - if you don't have a copy, it is freely available from Keith's link), "int int" is /not/ a syntax error. It is a /constraint violation. "int" and "long" are syntactically classified as "type specifiers", and the syntax for declarations allows any number of type specifiers. But the constrains given in 6.7.2 put limits on the combinations that are allowed. "int int" is not on that list, so it is a constraint error. "long long int" /is/ on the list, and the type specifiers can be re-ordered, so "long int long" is fine (it's a 64-bit signed integer type on the Arduino). I believe the difference between syntax errors and constrain violations in a case like this is purely for historical reasons. C++ has the same rules, but the standards are not as explicit about syntax and constraints. (For an alternative way to consider handling of "long" and "short" in C, you might enjoy this proposal: <https://www.open-std.org/JTC1/sc22/wg21/docs/papers/2018/p0989r0.pdf>)
Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar
What attributes of a programming language simplify its use? gah4 <gah4@u.washington.edu> - 2022-12-01 14:20 -0800
Re: What attributes of a programming language simplify its use? gah4 <gah4@u.washington.edu> - 2022-12-02 02:09 -0800
Re: What attributes of a programming language simplify its use? Thomas Koenig <tkoenig@netcologne.de> - 2022-12-03 10:25 +0000
Re: What attributes of a programming language simplify its use? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-12-03 22:16 +0100
Re: What attributes of a programming language simplify its use? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-12-06 09:56 -0800
Re: What attributes of a programming language simplify its use? gah4 <gah4@u.washington.edu> - 2022-12-06 12:43 -0800
Re: What attributes of a programming language simplify its use? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2022-12-07 10:14 +0000
Re: What attributes of a programming language simplify its use? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-12-07 12:13 +0100
Re: What attributes of a programming language simplify its use? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-12-07 17:53 -0800
Re: What attributes of a programming language simplify its use? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-12-08 21:42 +0100
Re: What attributes of a programming language simplify its use? gah4 <gah4@u.washington.edu> - 2022-12-08 14:44 -0800
Re: C types, was What attributes of a programming language simplify its use? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2022-12-09 15:01 +0100
Re: C types, was What attributes of a programming language simplify its use? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-12-08 18:35 -0800
Re: C types, was What attributes of a programming language simplify its use? David Brown <david.brown@hesbynett.no> - 2022-12-09 13:21 +0100
Re: What attributes of a programming language simplify its use? gah4 <gah4@u.washington.edu> - 2022-12-12 00:00 -0800
Re: C types, was What attributes of a programming language simplify its use? "marb...@yahoo.co.uk" <marblypup@yahoo.co.uk> - 2022-12-09 07:40 -0800
Re: C types, was What attributes of a programming language simplify its use? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2022-12-11 10:45 +0000
Simple to implement and to use Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-12-11 19:41 +0200
Re: What attributes of a programming language simplify its use? Christopher F Clark <christopher.f.clark@compiler-resources.com> - 2022-12-03 23:33 +0000
Re: What attributes of a programming language simplify its use? gah4 <gah4@u.washington.edu> - 2022-12-03 17:15 -0800
csiph-web