One feature that I find makes them easier to use, and harder to implement, is no reserved words.
[I take your point, but in PL/I you can say:
IF THEN = ELSE THEN BEGIN = IF; ELSE END = IF;
COBOL famously has too many reserved words but PL/I overreacted. -John]
We had the "What attributes of a programming language simplify its implementation?" discussion.
It seems, though, that languages are implemented a small number of
times, and used many times. So, designing for ease of use, instead of
ease of implementation makes more sense.
(Especially if you want a lot of people to want to use it.)
One feature that I find makes them easier to use, and harder to
implement, is no reserved words.
gah4 <gah4@u.washington.edu> schrieb:
One feature that I find makes them easier to use, and harder to
implement, is no reserved words.
I think this is more a matter of extensibility than of ease of use,
but both are somewhat intertwined.
Adding a new reserved word is a breaking change, especially if that
word is often used. See "new" in C++, which was something reasonable
to use in C, and is reserved in C++.
The discussion on reserved words versus keywords reminds me of
decisions we made while building Yacc++. It is worth noting that we
(both of its developers) worked at Pr1me computer where PL/I dialects
were the key programming language used in build both the OS and the compilers, so we were likely highly influenced by that.
IMO C basic syntax is a bad base. As long as declarations and
expressions can be distinguished only by the type of an identifier (type
name or variable name) it's not a good idea to add new keywords that can
be confused with variable or type names. Instead weird constructs like
"long long" for int64_t have been introduced, while "int int" stays equivalent to "int".
long long and int64_t are not the same (though int64_t may be the same
type as long long in a given implementation). long long is *at least* 64 bits. int64_t is *exactly* 64 bits, and must have a 2's-complement representation and no padding bits. "int int" is a syntax error.
(I'm not arguing that C's integer type system isn't overly complicated.)
In the early days of 64 bit computing, which I mostly remember from
the DEC Alpha, C compilers made long the 64 bit type.
That, then, broke too much software assuming long was 32 bits.
So then we got long long as the (close enough to) reliable 64 bit
type.
Maybe in a few years, we will have the long long long 128 bit type.
Hans-Peter Diettrich <DrDiettrich1@netscape.net> writes:
IMO C basic syntax is a bad base. As long as declarations and
expressions can be distinguished only by the type of an identifier (type
name or variable name) it's not a good idea to add new keywords that can
be confused with variable or type names.
Instead weird constructs like
"long long" for int64_t have been introduced, while "int int" stays
equivalent to "int".
long long and int64_t are not the same (though int64_t may be the same
type as long long in a given implementation). long long is *at least* 64 bits. int64_t is *exactly* 64 bits, and must have a 2's-complement representation and no padding bits.
"int int" is a syntax error.
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?
In former times it was much easier to decide with a single basic type id (int...) and type modifiers (long...).
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.
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.
DoDi
[This is getting close to comp.lang.c but I'm OK with a little more discussion of the design decisions in C's very messy declarations. -John]
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.
DoDi
[This is getting close to comp.lang.c but I'm OK with a little more discussion of the design decisions in C's very messy declarations. -John]
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.
On Thursday, December 8, 2022 at 12:45:04 PM UTC-8, Hans-Peter Diettrich wrote:
(snip)
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.
DoDi
[This is getting close to comp.lang.c but I'm OK with a little more
discussion of the design decisions in C's very messy declarations. -John]
Now we can get closer to compilers.
I suspect that it isn't a syntax error, though it will depend on how the compiler is written.
The compiler (parser) can accept any combination of the specifiers,
and even more than one of them, and then later the compiler decides
that the ones given are not valid.
There was a story many years ago, about a compiler with only one error message: "SYNTAX ERROR". (Likely in the days of upper case only.)
In any case, it is often easier to write the parser more general than
the actual language, and then flag them later.
But also, the same can be done for the language standard.
As well as I know it, in early C variables default to int. Later, it
was required that they be declared, but the default type was still
int.
Instead weird constructs like
"long long" for int64_t have been introduced, while "int int" stays equivalent to "int".
From nearly 40 years
of C programming, I've concluded that having "int" be the "natural" size of >integer is more of a liability than an asset.)
(I'm not arguing that C's integer type system isn't overly complicated.)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 58:34:18 |
Calls: | 6,712 |
Files: | 12,243 |
Messages: | 5,355,631 |