Liste des Groupes | Revenir à cl c |
On 01/11/2024 19:05, Bart wrote:On 01/11/2024 17:35, David Brown wrote:
I don't think it's just opinion.Fair enough.>>
What you have written here is all correct, but a more common method would be to avoid having three printf's :
>
void shout_a_number(int n) {
printf( (const char* []) { "ONE", "TWO", "THREE" } [n] );
}
>
That's more likely to match what people would want.
I was also trying to show that all elements are evaluated, so each has to have some side-effect to illustrate that.
>That's a matter of opinion and design choice, rather than being requirements for a "true" select construct.
A true N-way-select construct (C only really has ?:) would evaluate only one, and would deal with an out-of-range condition.
You are free to choose the rules you want for your own language, but you are not free to dictate what you think the rules should be for others. (You are welcome to /opinions/, of course.)All such multiway constructs in my languages (there are 4, one of which the job of both 'if' and C's ?:) have an optional else branch. A missing 'else' has an notional 'void' type.
>OK, if that's what you want. My preference, if I were putting together what /I/ thought was an idea language for /my/ use, would be heavy use of explicit specifications and contracts for code, so that a default/else branch is either disallowed (if there the selection covers all legal values) or required (if the selection is abbreviated). A default value "just in case" is, IMHO, worse than useless.
(In my implementations, a default/else branch value must be provided if the whole thing is expected to return a value.)
>
Les messages affichés proviennent d'usenet.