Re: "A diagram of C23 basic types"

Liste des GroupesRevenir à cl c  
Sujet : Re: "A diagram of C23 basic types"
De : cr88192 (at) *nospam* gmail.com (BGB)
Groupes : comp.lang.c
Date : 10. Apr 2025, 19:47:42
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vt93rd$3jj8k$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
User-Agent : Mozilla Thunderbird
On 4/10/2025 2:53 AM, David Brown wrote:
On 09/04/2025 21:11, bart wrote:
On 09/04/2025 18:26, BGB wrote:
On 4/9/2025 8:01 AM, David Brown wrote:
On 09/04/2025 11:49, Michael S wrote:
On Fri, 4 Apr 2025 02:57:10 -0000 (UTC)
Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
>
On Thu, 3 Apr 2025 21:48:40 +0100, bart wrote:
>
Commas are overwhelmingly used to separate list elements in
programming languages.
>
Not just separate, but terminate.
>
I disagree. I am in favor of optional trailing commas rather than
mandatory ones.
>
I am certainly in favour of them for things like initialiser lists and enum declarations.
>
>
All the reasonable languages allow
trailing commas.
>
Are your sure that C Standard does not allow trailing commas?
That is, they are obviously legal in initializer lists.
All compilers that I tried reject trailing comma in function calls.
>
...
But is it (rejection) really required by the Standard? I don't know.
>
>
>
Yes.  The syntax (in 6.5.2p1) is :
>
postfix-expression:
     ...
     postfix-expression ( argument-expression-list opt )
     ...
>
argument-expression-list :
     argument-expression
     argument-expression-list , argument-expression
>
>
>
I don't think it is unreasonable to suggest that it might be nice to allow a trailing comma, at least in variadic function calls, but the syntax of C does not allow it.
>
>
Yeah, pretty much.
>
>
It might have also been interesting if C allowed optional named arguments:
int foo(int x=3, int y=4)
{
   return x+y;
}
>
foo() => 7
foo(.y=2) => 5
>
Likely would be following any fixed arguments (if present), and likely (for sake of implementation sanity) named arguments and varargs being mutually exclusive (alternative being that named arguments precede varargs if both are used).
>
Well, at least ".y=val" as "y: val" likely wouldn't go over well even if it is what several other languages with this feature used (well or, "y=val", which is used in some others).
>
In the most likely case, the named argument form would be transformed into the equivalent fixed argument form at compile time.
   So: "foo(.y=2)" would be functionally equivalent to "foo(3,2)".
>
There are all sorts of problems in adding this to C. For example, this is legal:
>
   void F(int a, float b, char* c);
   void F(int c, float a, char* b);
   void F(int b, float c, char* a) {}
>
The sets of parameter names are all different (and that's in the same file!); which is the official set?
 C has had flexibility here for all sorts of reasons.  But if named parameters were to be added to the language without significant extra syntax, then this particular issue could be solved in at least two very simple ways.  Either say that named parameter syntax can only be used if all of the function's declarations in the translation unit have consistent naming, or say that the last declaration in scope is the one used.  (My guess would be that the later, with compilers offering warnings about the former.)
 Of course that lets someone declare "void f(int a, int b);" in one file and "void f(int b, int a);" in a different one - but that does not noticeably change the kind of mixups already available to the undisciplined programmer, and it is completely eliminated by the standard practice of using shared headers for declarations.
 
My likely rule here:
If named arguments were used, the prototypes are required to match exactly (including names);
At least within a translation unit.
However, this would only apply to prototypes whose arguments have initializer values. So, those like in BartC's example would be unaffected (but, also, could not be used with names either).
In cases where prototypes differ between translation units, it would be implementation defined. Most likely, it would depend on what was in effect at the call-site of the function.

 
>
Another is to do with defining default values (essential if named arguments are to be fully used). First, similar thing to the above:
>
   void F(int a = x + y);
   void F(int a = DEFAULT);
>
 Default arguments are most certainly not essential to make named parameters useful.  They /can/ be a nice thing to have, but they are merely icing on the cake.  Still, there is an obvious and C-friendly way to handle this too - the default values must be constant expressions.
 A much clearer issue with a named parameter syntax like this is that something like "foo(b = 1, a = 2);" is already valid in C and means something significantly different.  You'd need a different syntax.
 Fundamental matters such as this are best decided early in the design of a language, rather than bolted on afterwards.  Named parameters is something I like in languages, but it's not easy to add to established languages.
 
My thinking is that they would not change the behavior of existing functions or prototypes, but would incur new some rules when used.
If a named argument is used, then it needs to have an assigned value, even if 0.
Similarly, the initializer values would be required to be a compile-time constant (possibly with some additional limits relative to what is allowed for initializers for global variants, say only allowing for primitive literals but no compound literals nor taking the address of a variable or function).
If no initializer is used, it is a fixed argument, and by extension may not be used as a named argument.
So, for example:
   void foo1(float x, float y, float z);       //fine, traditional
   void foo2(float x, float y=0, float z=0);   //fine
   void foo3(float x, float y=0, float z);     //bad, not allowed
   void foo4(float x=0, float y, float z);     //bad, not allowed
   void foo5(float x=0, float y=0, float z=0);  //fine
Likewise:
   foo1(1,2,3);  //fine
   foo1(.x=1, .y=2, .z=3);  //bad, these are not named arguments
   foo2(1, .y=2, .z=3);     //fine
   foo2(.x=1, .y=2, .z=3);  //bad, x is a fixed argument
   foo5(.x=1, .y=2, .z=3);  //fine
   foo5(1,2,3);             //maybe bad, 1
1: named arguments are to be named. But, maybe, using them as positional arguments will work and behave as-if the names were given, making it equivalent to the preceding.
IIRC, all this is similar to the behavior in C#.

Still, the C++ crowd regularly try to figure out how named parameters could be added to C++.  I think they will figure it out eventually.  C++ adds a number of extra complications here that C does not have, but once they have a decent solution, C could probably adopt it.  Let C++ pave the way on new concepts, and C can copy the bits that suit once C++ has done the field testing - that's part of the C standard committee philosophy, and a good way to handle these things.
 
Possibly.
I was more thinking one could have them partly because they are a nice thing to have in some scenarios.
Whether or not they could be adapted to C++, dunno.
Personally I don't really use C++ much, and my compiler's support for it is pretty lacking. To what extent it supports C++ is mostly to what extent C++ overlaps C and BS2 (which, is a bit hit or miss, given BS2 uses a Java-like object model, sorta).
The BS2 model does differ slightly from Java though:
   Allows dynamic objects (like in ActionScript)
     New fields can be added dynamically per-object.
     Internally, it is still a Class/Instance object.
     But, has a hidden JS style object internally.
   It is possible for scope to be delegated through designated members.
     It is vaguely similar to the Self scoping model.
     But, only applies to what is visible at compile time.
The original BGBScript had allowed a fully mutable object scoping model (like in the Self language), however, this was rarely used directly; and was complex and expensive to support efficiently (and part of why this VM was abandoned, dealing with this stuff just got too complicated in terms of the implementation).
In BGBCC's BS support and in the rules for my BGBScript2 language, the scope handling is limited to what is visible at compile time. If an interpreted version of BS were revived, dunno.
To some extent, the namespace scoping can be seen as an instance of this, albeit with the "objects" only existing at compile time (something like C++'s "using namespace whatever;" effectively creating an implicit variable which delegates the scope for the current namespace "object" to another namespace "object").
This also differs from JavaScript which only allows for a single "prototype" ("__proto__") per object, and forms a simple DAG; rather than supporting a free-form graph with possible cycles being allowed (so, is arguably a much simpler model vs that used in Self).
...

Date Sujet#  Auteur
2 Apr 25 * "A diagram of C23 basic types"327Alexis
2 Apr 25 +* Re: "A diagram of C23 basic types"4Lawrence D'Oliveiro
3 Apr 25 i`* Re: "A diagram of C23 basic types"3BGB
3 Apr 25 i `* Re: "A diagram of C23 basic types"2Lawrence D'Oliveiro
4 Apr 25 i  `- Re: "A diagram of C23 basic types"1BGB
2 Apr 25 +* Re: "A diagram of C23 basic types"9Janis Papanagnou
2 Apr 25 i+* Re: "A diagram of C23 basic types"6Kaz Kylheku
3 Apr 25 ii`* Re: "A diagram of C23 basic types"5Janis Papanagnou
3 Apr 25 ii +* Re: "A diagram of C23 basic types"3David Brown
3 Apr 25 ii i`* Re: "A diagram of C23 basic types"2Janis Papanagnou
3 Apr 25 ii i `- Re: "A diagram of C23 basic types"1BGB
3 Apr 25 ii `- Re: "A diagram of C23 basic types"1BGB
2 Apr 25 i+- Re: "A diagram of C23 basic types"1David Brown
3 Apr 25 i`- Re: "A diagram of C23 basic types"1Tim Rentsch
2 Apr 25 +* Re: "A diagram of C23 basic types"307bart
2 Apr 25 i+* Re: "A diagram of C23 basic types"281Muttley
2 Apr 25 ii+* Re: "A diagram of C23 basic types"251David Brown
2 Apr 25 iii+* Re: "A diagram of C23 basic types"247Muttley
2 Apr 25 iiii+* Re: "A diagram of C23 basic types"173Thiago Adams
2 Apr 25 iiiii`* Re: "A diagram of C23 basic types"172Muttley
2 Apr 25 iiiii +* Re: "A diagram of C23 basic types"170bart
2 Apr 25 iiiii i+* Re: "A diagram of C23 basic types"58Muttley
2 Apr 25 iiiii ii+* Re: "A diagram of C23 basic types"5Janis Papanagnou
3 Apr 25 iiiii iii+* Re: "A diagram of C23 basic types"2Janis Papanagnou
3 Apr 25 iiiii iiii`- Re: "A diagram of C23 basic types"1Janis Papanagnou
3 Apr 25 iiiii iii`* Re: "A diagram of C23 basic types"2David Brown
3 Apr 25 iiiii iii `- Re: "A diagram of C23 basic types"1BGB
3 Apr 25 iiiii ii+* Re: "A diagram of C23 basic types"49bart
3 Apr 25 iiiii iii+* Re: "A diagram of C23 basic types"46Kaz Kylheku
3 Apr 25 iiiii iiii+* Re: "A diagram of C23 basic types"43Keith Thompson
3 Apr 25 iiiii iiiii+* Re: "A diagram of C23 basic types"41BGB
3 Apr 25 iiiii iiiiii`* Re: "A diagram of C23 basic types"40Kaz Kylheku
3 Apr 25 iiiii iiiiii +* Re: "A diagram of C23 basic types"36bart
4 Apr 25 iiiii iiiiii i+* Re: "A diagram of C23 basic types"31Lawrence D'Oliveiro
9 Apr 25 iiiii iiiiii ii`* Re: "A diagram of C23 basic types"30Michael S
9 Apr 25 iiiii iiiiii ii +* Re: "A diagram of C23 basic types"21David Brown
9 Apr 25 iiiii iiiiii ii i+* Re: "A diagram of C23 basic types"17BGB
9 Apr 25 iiiii iiiiii ii ii`* Re: "A diagram of C23 basic types"16bart
10 Apr 25 iiiii iiiiii ii ii `* Re: "A diagram of C23 basic types"15David Brown
10 Apr 25 iiiii iiiiii ii ii  +* Re: "A diagram of C23 basic types"5Michael S
12 Apr06:43 iiiii iiiiii ii ii  i`* Re: "A diagram of C23 basic types"4Lawrence D'Oliveiro
12 Apr15:10 iiiii iiiiii ii ii  i +- Re: "A diagram of C23 basic types"1James Kuyper
12 Apr16:21 iiiii iiiiii ii ii  i `* Re: "A diagram of C23 basic types"2David Brown
12 Apr20:27 iiiii iiiiii ii ii  i  `- Re: "A diagram of C23 basic types"1BGB
10 Apr 25 iiiii iiiiii ii ii  +* Re: "A diagram of C23 basic types"4Muttley
10 Apr 25 iiiii iiiiii ii ii  i`* Re: "A diagram of C23 basic types"3bart
10 Apr 25 iiiii iiiiii ii ii  i +- Re: "A diagram of C23 basic types"1Muttley
12 Apr06:44 iiiii iiiiii ii ii  i `- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
10 Apr 25 iiiii iiiiii ii ii  +* Re: "A diagram of C23 basic types"4bart
10 Apr 25 iiiii iiiiii ii ii  i`* Re: "A diagram of C23 basic types"3David Brown
10 Apr 25 iiiii iiiiii ii ii  i `* Re: "A diagram of C23 basic types"2bart
10 Apr 25 iiiii iiiiii ii ii  i  `- Re: "A diagram of C23 basic types"1David Brown
10 Apr 25 iiiii iiiiii ii ii  `- Re: "A diagram of C23 basic types"1BGB
9 Apr 25 iiiii iiiiii ii i`* Re: "A diagram of C23 basic types"3Keith Thompson
12 Apr06:42 iiiii iiiiii ii i `* Re: "A diagram of C23 basic types"2Lawrence D'Oliveiro
12 Apr21:46 iiiii iiiiii ii i  `- Re: "A diagram of C23 basic types"1Keith Thompson
9 Apr 25 iiiii iiiiii ii +* Re: "A diagram of C23 basic types"7Tim Rentsch
9 Apr 25 iiiii iiiiii ii i+* Re: "A diagram of C23 basic types"3Keith Thompson
14 Apr10:10 iiiii iiiiii ii ii`* Re: "A diagram of C23 basic types"2Tim Rentsch
14 Apr12:08 iiiii iiiiii ii ii `- Re: "A diagram of C23 basic types"1Keith Thompson
10 Apr 25 iiiii iiiiii ii i`* Re: "A diagram of C23 basic types"3Michael S
14 Apr09:59 iiiii iiiiii ii i `* Re: "A diagram of C23 basic types"2Tim Rentsch
14 Apr10:44 iiiii iiiiii ii i  `- Re: "A diagram of C23 basic types"1Michael S
9 Apr 25 iiiii iiiiii ii `- Re: "A diagram of C23 basic types"1Kaz Kylheku
4 Apr 25 iiiii iiiiii i`* Re: "A diagram of C23 basic types"4Waldek Hebisch
4 Apr 25 iiiii iiiiii i +* Re: "A diagram of C23 basic types"2Keith Thompson
4 Apr 25 iiiii iiiiii i i`- Re: "A diagram of C23 basic types"1Waldek Hebisch
8 Apr 25 iiiii iiiiii i `- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
3 Apr 25 iiiii iiiiii +* Re: "A diagram of C23 basic types"2Keith Thompson
4 Apr 25 iiiii iiiiii i`- Re: "A diagram of C23 basic types"1Kaz Kylheku
4 Apr 25 iiiii iiiiii `- Re: "A diagram of C23 basic types"1Michael S
4 Apr 25 iiiii iiiii`- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
3 Apr 25 iiiii iiii+- Re: "A diagram of C23 basic types"1Muttley
3 Apr 25 iiiii iiii`- Re: "A diagram of C23 basic types"1Keith Thompson
3 Apr 25 iiiii iii+- Re: "A diagram of C23 basic types"1David Brown
4 Apr 25 iiiii iii`- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
3 Apr 25 iiiii ii`* Re: "A diagram of C23 basic types"3Muttley
4 Apr 25 iiiii ii `* Re: "A diagram of C23 basic types"2Muttley
4 Apr 25 iiiii ii  `- Re: "A diagram of C23 basic types"1Muttley
4 Apr 25 iiiii i`* Re: "A diagram of C23 basic types"111Lawrence D'Oliveiro
4 Apr 25 iiiii i +- Re: "A diagram of C23 basic types"1Keith Thompson
7 Apr 25 iiiii i +* Re: "A diagram of C23 basic types"60candycanearter07
7 Apr 25 iiiii i i+* Re: "A diagram of C23 basic types"58Janis Papanagnou
8 Apr 25 iiiii i ii+- Re: "A diagram of C23 basic types"1candycanearter07
14 Apr05:33 iiiii i ii`* Re: "A diagram of C23 basic types"56Lawrence D'Oliveiro
14 Apr18:40 iiiii i ii `* Re: "A diagram of C23 basic types"55candycanearter07
14 Apr18:46 iiiii i ii  +* Re: "A diagram of C23 basic types"2Kaz Kylheku
15 Apr08:41 iiiii i ii  i`- Re: "A diagram of C23 basic types"1Janis Papanagnou
14 Apr19:36 iiiii i ii  `* Re: "A diagram of C23 basic types"52BGB
14 Apr23:15 iiiii i ii   +- Re: "A diagram of C23 basic types"1Keith Thompson
14 Apr23:33 iiiii i ii   `* Re: "A diagram of C23 basic types"50Lawrence D'Oliveiro
14 Apr23:56 iiiii i ii    +* Re: "A diagram of C23 basic types"30Keith Thompson
15 Apr00:41 iiiii i ii    i+* Re: "A diagram of C23 basic types"19Lawrence D'Oliveiro
15 Apr01:57 iiiii i ii    ii+- Re: "A diagram of C23 basic types"1Keith Thompson
15 Apr04:25 iiiii i ii    ii`* Re: "A diagram of C23 basic types"17James Kuyper
15 Apr05:11 iiiii i ii    ii +* Re: "A diagram of C23 basic types"9Lawrence D'Oliveiro
15 Apr15:06 iiiii i ii    ii i`* Re: "A diagram of C23 basic types"8James Kuyper
15 Apr23:56 iiiii i ii    ii i +* Re: "A diagram of C23 basic types"4Keith Thompson
16 Apr01:04 iiiii i ii    ii i i+- Re: "A diagram of C23 basic types"1Chris M. Thomasson
16 Apr01:53 iiiii i ii    ii i i`* Re: "A diagram of C23 basic types"2James Kuyper
17 Apr16:56 iiiii i ii    ii i i `- Re: "A diagram of C23 basic types"1David Brown
15 Apr23:58 iiiii i ii    ii i `* Re: "A diagram of C23 basic types"3Lawrence D'Oliveiro
15 Apr06:00 iiiii i ii    ii `* Re: "A diagram of C23 basic types"7BGB
15 Apr02:46 iiiii i ii    i`* Re: "A diagram of C23 basic types"10Chris M. Thomasson
15 Apr01:43 iiiii i ii    `* Re: "A diagram of C23 basic types"19BGB
8 Apr 25 iiiii i i`- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
7 Apr 25 iiiii i `* Re: "A diagram of C23 basic types"49bart
4 Apr 25 iiiii `- Re: "A diagram of C23 basic types"1Lawrence D'Oliveiro
2 Apr 25 iiii+* Re: "A diagram of C23 basic types"2Michael S
2 Apr 25 iiii`* Re: "A diagram of C23 basic types"71David Brown
2 Apr 25 iii`* Re: "A diagram of C23 basic types"3Kaz Kylheku
2 Apr 25 ii`* Re: "A diagram of C23 basic types"29Waldek Hebisch
5 Apr 25 i`* Re: "A diagram of C23 basic types"25Philipp Klaus Krause
3 Apr 25 +* Re: "A diagram of C23 basic types"2Michael S
11 Apr 25 +* Re: "A diagram of C23 basic types"2Tim Rentsch
11 Apr 25 `* Re: "A diagram of C23 basic types"2Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal