Thread View: comp.lang.c
5 messages
5 total messages
Started by Kaz Kylheku
Wed, 07 Oct 2026 00:42
Re: Taming The Switch-Statement
Author: Kaz Kylheku
Date: Wed, 07 Oct 2026 00:42
Date: Wed, 07 Oct 2026 00:42
118 lines
6426 bytes
6426 bytes
On 2026-10-05, bart <bc@freeuk.com> wrote: > On 05/10/2026 22:48, Kaz Kylheku wrote: >> On 2026-10-05, bart <bc@freeuk.com> wrote: >>> A lot of what big compilers do is what used to be called 'linting'. >> >> I don't suspect you can get rid of that in any language. >> >> The reason is that as experience with the given language grows, it is >> found that programmers make certain mistakes, where making formal >> syntactic and semantic rules against those mistakes, and sticking >> them into the language, would be a poor idea. >> >> At some point, you are trying to design a pencil that cannot be >> used to draw an optical illusion. >> >>> I don't consider that to be their job, which should be to verify my >>> program and turn it into runnable code, and not give opinions. >> >> That's a waste of potential; why would you refuse a machine that >> can apply hundreds of deterministic pattern matching rules against >> possible trouble situations in hundreds of thousands of lines of code, >> in seconds. > > I simply don't care about it. I don't have seconds to waste either. Your implementation of the same thing would take milliseconds, of course. > Here are some common C-compiling scenarios: > > * You want to build a finished, working, debugged program from source. > This does need the compiler spending time double-guessing the author's > intentions, and in any case the person building it is not going to > mess with the source > > * You are building a program which is machine-transpiled C code. It > should be valid C with no errors. (If there are, that is the > responsibility of the transpiler author.) But again you don't care > about style, or the fact that there are lots of unused labels for > example (common in such code) Then * you still want linting in the source language. * even if you are generating C you could do something wrong that can be flagged by a C linter --- and you are in the best possible position to do something about it. THin about it: suppose you transpile 500,000 lines of code to about as many lines of C, and the C linter identifies 50,000 instances of the same error. You may be able to fix all of them with a one line change in your translator!!! (By contrast, if you have 50,000 individually hand-written instances of a lint violation, good luck ...) If you're in a great position to take advantage of linting, do it. > > * You've made a one-line change and just quickly want to run it again. > You don't want a style analysis on the same few thousand lines that > has already been recently done. > > Linting is something you might do every so often - not for routine builds. If you are in a closed loop already in which you have addressed all linting errors or else turned off specific diagnostics you're not interested in fixing, in fact you do follow up to all new lint issues caused by a change. It becomes like any other diagnostic. > However, with C compilers it is common for warnings to be generated > rather than hard errors. > > This is blurring the line between compiling and linting: No diagnosable situation in C according to ISO C is required to terminate translation immediately, or mark it unsuccessful. All diagnostic requirements are linting. :) > * Is the transgression serious? Is so then report an error and fail to > compile For instance, converting among incompatible pointer types without a cast is a required diagnostic by ISO C; it is "serious" in that it defeats the type system and can be the root cause of a crash. But it's just a formality in that you can insert the cast to request it and then the conversion doesn't require a diagnostic. (If the lack of the cast formality was the only thing stopping it from being correct, then it is correct; otherwise it stays incorrect.) The bottom line is that a program which converts among incompatible pointer types is not necessarily incorrect. It can be translated and it can work. There has been historically a "loosey goosey" attitude across the C landscape whereby the expectation is that compilers try to accept code and at worst grumble about it. A lot of the time this would actually just work by dumb luck; weird code that worked on one system on its compiler worked on another system with its compiler, and so the /apparent/ work of porting something to a new platform was reduced, even if it was by fluke. You are right in that this does not fly in all necks of the woods. Can you imagine Haskell people saying, oh, type checks are just gonna be warnings now ... :) Postel's Law, being "liberal in what you accept [etc]", isn't such a great idea. Hypothesis: was Postel inspired to that by exposure to C? History has brought us to a kind of reckoning. Attitudes of new people are different, the compilers have marched on, yet things are saddled with the historic baggage at the same time. -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca
Re: Taming The Switch-Statement
Author: bart
Date: Wed, 07 Oct 2026 12:52
Date: Wed, 07 Oct 2026 12:52
127 lines
6291 bytes
6291 bytes
On 07/10/2026 01:42, Kaz Kylheku wrote:
> On 2026-10-05, bart <bc@freeuk.com> wrote:
>> On 05/10/2026 22:48, Kaz Kylheku wrote:
>>> On 2026-10-05, bart <bc@freeuk.com> wrote:
>>>> A lot of what big compilers do is what used to be called 'linting'.
>>>
>>> I don't suspect you can get rid of that in any language.
>>>
>>> The reason is that as experience with the given language grows, it is
>>> found that programmers make certain mistakes, where making formal
>>> syntactic and semantic rules against those mistakes, and sticking
>>> them into the language, would be a poor idea.
>>>
>>> At some point, you are trying to design a pencil that cannot be
>>> used to draw an optical illusion.
>>>
>>>> I don't consider that to be their job, which should be to verify my
>>>> program and turn it into runnable code, and not give opinions.
>>>
>>> That's a waste of potential; why would you refuse a machine that
>>> can apply hundreds of deterministic pattern matching rules against
>>> possible trouble situations in hundreds of thousands of lines of code,
>>> in seconds.
>>
>> I simply don't care about it. I don't have seconds to waste either.
>
> Your implementation of the same thing would take milliseconds, of
> course.
I wouldn't want it at all.
But if I had to implement it, I don't know how long it would take. If I
found that it was taking disproportionately long (compared to the main
task of generating a binary), then I would separate it out from the
compiler, as I've suggested.
For example, if 90% of compile-time was spent on it.
>> Here are some common C-compiling scenarios:
>>
>> * You want to build a finished, working, debugged program from source.
>> This does need the compiler spending time double-guessing the author's
>> intentions, and in any case the person building it is not going to
>> mess with the source
>>
>> * You are building a program which is machine-transpiled C code. It
>> should be valid C with no errors. (If there are, that is the
>> responsibility of the transpiler author.) But again you don't care
>> about style, or the fact that there are lots of unused labels for
>> example (common in such code)
>
> Then
>
> * you still want linting in the source language.
Possibly. I don't care too much about that either. In my stuff, I do
very little in the way of advisory reports, which are only enabled
infrequently.
But the context here is using linting to warn about things that are a
consequence of C's design, such as switch 'break' that is the subject of
the thread.
I prefer to deal with that with a better language design.
> * even if you are generating C you could do something wrong
> that can be flagged by a C linter --- and you are in the best possible
> position to do something about it. THin about it: suppose you transpile
> 500,000 lines of code to about as many lines of C, and the C linter
> identifies 50,000 instances of the same error.
Example?
For transpiled C, the only problems in the C should be related to the
translation process (that is, in the transpiler source) and not to the
program being transpiled.
Once those are fixed, there is usually little need to look at the
generated C, and there should never be any messages about it.
Unless somebody decides to ramp up the warnings, but every generated C
file has a comment with suggested build instructions.
>> * Is the transgression serious? Is so then report an error and fail to
>> compile
>
> For instance, converting among incompatible pointer types without a cast
> is a required diagnostic by ISO C; it is "serious" in that it defeats
> the type system and can be the root cause of a crash.
Then it should be an error. If I try and compile this:
int *p, *q;
char *r;
p=r;
I get:
gcc 14 error
gcc 10 warning
clang 19 warning
tcc warning
bcc error
Clang is surprising here as it's normally a lot stricter by default than
gcc.
But why are even some compilers not downright failing this? If such an
assignment is known to be safe for a particular program, then it is a
small imposition to use a cast.
> But it's just a formality in that you can insert the cast to request
> it and then the conversion doesn't require a diagnostic.
> (If the lack of the cast formality was the only thing stopping it from
> being correct, then it is correct; otherwise it stays incorrect.)
>
> The bottom line is that a program which converts among incompatible
> pointer types is not necessarily incorrect. It can be translated
> and it can work.
Requiring a cast makes a program safer as it forces you to think about
it if compilation can't proceed otherwise.
Re: Taming The Switch-Statement
Author: Chris M. Thomasson
Date: Wed, 07 Oct 2026 21:06
Date: Wed, 07 Oct 2026 21:06
69 lines
4386 bytes
4386 bytes
On 10/7/2026 5:52 AM, bart wrote: > On 07/10/2026 01:42, Kaz Kylheku wrote: >> On 2026-10-05, bart <bc@freeuk.com> wrote: >>> On 05/10/2026 22:48, Kaz Kylheku wrote: >>>> On 2026-10-05, bart <bc@freeuk.com> wrote: >>>>> A lot of what big compilers do is what used to be called 'linting'. >>>> >>>> I don't suspect you can get rid of that in any language. >>>> >>>> The reason is that as experience with the given language grows, it is >>>> found that programmers make certain mistakes, where making formal >>>> syntactic and semantic rules against those mistakes, and sticking >>>> them into the language, would be a poor idea. >>>> >>>> At some point, you are trying to design a pencil that cannot be >>>> used to draw an optical illusion. >>>> >>>>> I don't consider that to be their job, which should be to verify my >>>>> program and turn it into runnable code, and not give opinions. >>>> >>>> That's a waste of potential; why would you refuse a machine that >>>> can apply hundreds of deterministic pattern matching rules against >>>> possible trouble situations in hundreds of thousands of lines of code, >>>> in seconds. >>> >>> I simply don't care about it. I don't have seconds to waste either. >> >> Your implementation of the same thing would take milliseconds, of >> course. > > I wouldn't want it at all. > > But if I had to implement it, I don't know how long it would take. If I > found that it was taking disproportionately long (compared to the main > task of generating a binary), then I would separate it out from the > compiler, as I've suggested. > > For example, if 90% of compile-time was spent on it. > > >>> Here are some common C-compiling scenarios: >>> >>> * You want to build a finished, working, debugged program from source. >>> This does need the compiler spending time double-guessing the >>> author's >>> intentions, and in any case the person building it is not going to >>> mess with the source >>> >>> * You are building a program which is machine-transpiled C code. It >>> should be valid C with no errors. (If there are, that is the >>> responsibility of the transpiler author.) But again you don't care >>> about style, or the fact that there are lots of unused labels for >>> example (common in such code) >> >> Then >> >> * you still want linting in the source language. > > Possibly. I don't care too much about that either. In my stuff, I do > very little in the way of advisory reports, which are only enabled > infrequently. > > But the context here is using linting to warn about things that are a > consequence of C's design, such as switch 'break' that is the subject of > the thread. > > I prefer to deal with that with a better language design. Are you making a "new" C?[...]
Re: Taming The Switch-Statement
Author: bart
Date: Wed, 07 Oct 2026 22:31
Date: Wed, 07 Oct 2026 22:31
85 lines
5084 bytes
5084 bytes
On 07/10/2026 22:06, Chris M. Thomasson wrote: > On 10/7/2026 5:52 AM, bart wrote: >> On 07/10/2026 01:42, Kaz Kylheku wrote: >>> On 2026-10-05, bart <bc@freeuk.com> wrote: >>>> On 05/10/2026 22:48, Kaz Kylheku wrote: >>>>> On 2026-10-05, bart <bc@freeuk.com> wrote: >>>>>> A lot of what big compilers do is what used to be called 'linting'. >>>>> >>>>> I don't suspect you can get rid of that in any language. >>>>> >>>>> The reason is that as experience with the given language grows, it is >>>>> found that programmers make certain mistakes, where making formal >>>>> syntactic and semantic rules against those mistakes, and sticking >>>>> them into the language, would be a poor idea. >>>>> >>>>> At some point, you are trying to design a pencil that cannot be >>>>> used to draw an optical illusion. >>>>> >>>>>> I don't consider that to be their job, which should be to verify my >>>>>> program and turn it into runnable code, and not give opinions. >>>>> >>>>> That's a waste of potential; why would you refuse a machine that >>>>> can apply hundreds of deterministic pattern matching rules against >>>>> possible trouble situations in hundreds of thousands of lines of code, >>>>> in seconds. >>>> >>>> I simply don't care about it. I don't have seconds to waste either. >>> >>> Your implementation of the same thing would take milliseconds, of >>> course. >> >> I wouldn't want it at all. >> >> But if I had to implement it, I don't know how long it would take. If >> I found that it was taking disproportionately long (compared to the >> main task of generating a binary), then I would separate it out from >> the compiler, as I've suggested. >> >> For example, if 90% of compile-time was spent on it. >> >> >>>> Here are some common C-compiling scenarios: >>>> >>>> * You want to build a finished, working, debugged program from source. >>>> This does need the compiler spending time double-guessing the >>>> author's >>>> intentions, and in any case the person building it is not going to >>>> mess with the source >>>> >>>> * You are building a program which is machine-transpiled C code. It >>>> should be valid C with no errors. (If there are, that is the >>>> responsibility of the transpiler author.) But again you don't care >>>> about style, or the fact that there are lots of unused labels for >>>> example (common in such code) >>> >>> Then >>> >>> * you still want linting in the source language. >> >> Possibly. I don't care too much about that either. In my stuff, I do >> very little in the way of advisory reports, which are only enabled >> infrequently. >> >> But the context here is using linting to warn about things that are a >> consequence of C's design, such as switch 'break' that is the subject >> of the thread. >> >> I prefer to deal with that with a better language design. > > Are you making a "new" C?[...] I'm not making anything. I have long maintained a personal systems language which fixes most of my moans about C (and even deals with some of fir's needs, but those seem to change erratically). It would have been good for /someone else/ to have evolved C in a direction I'd have found useful, but current evolvement of C is not interesting to me and IMO misguided. Since I have my own solutions for the little coding I do now, this doesn't matter so much - let C aficionados be masochists if they want. But I am still interested in tooling (which has its own masochists!).
Re: Taming The Switch-Statement
Author: Chris M. Thomasson
Date: Tue, 27 Oct 2026 01:48
Date: Tue, 27 Oct 2026 01:48
93 lines
5359 bytes
5359 bytes
On 10/7/2026 3:31 PM, bart wrote: > On 07/10/2026 22:06, Chris M. Thomasson wrote: >> On 10/7/2026 5:52 AM, bart wrote: >>> On 07/10/2026 01:42, Kaz Kylheku wrote: >>>> On 2026-10-05, bart <bc@freeuk.com> wrote: >>>>> On 05/10/2026 22:48, Kaz Kylheku wrote: >>>>>> On 2026-10-05, bart <bc@freeuk.com> wrote: >>>>>>> A lot of what big compilers do is what used to be called 'linting'. >>>>>> >>>>>> I don't suspect you can get rid of that in any language. >>>>>> >>>>>> The reason is that as experience with the given language grows, it is >>>>>> found that programmers make certain mistakes, where making formal >>>>>> syntactic and semantic rules against those mistakes, and sticking >>>>>> them into the language, would be a poor idea. >>>>>> >>>>>> At some point, you are trying to design a pencil that cannot be >>>>>> used to draw an optical illusion. >>>>>> >>>>>>> I don't consider that to be their job, which should be to verify my >>>>>>> program and turn it into runnable code, and not give opinions. >>>>>> >>>>>> That's a waste of potential; why would you refuse a machine that >>>>>> can apply hundreds of deterministic pattern matching rules against >>>>>> possible trouble situations in hundreds of thousands of lines of >>>>>> code, >>>>>> in seconds. >>>>> >>>>> I simply don't care about it. I don't have seconds to waste either. >>>> >>>> Your implementation of the same thing would take milliseconds, of >>>> course. >>> >>> I wouldn't want it at all. >>> >>> But if I had to implement it, I don't know how long it would take. If >>> I found that it was taking disproportionately long (compared to the >>> main task of generating a binary), then I would separate it out from >>> the compiler, as I've suggested. >>> >>> For example, if 90% of compile-time was spent on it. >>> >>> >>>>> Here are some common C-compiling scenarios: >>>>> >>>>> * You want to build a finished, working, debugged program from source. >>>>> This does need the compiler spending time double-guessing the >>>>> author's >>>>> intentions, and in any case the person building it is not going to >>>>> mess with the source >>>>> >>>>> * You are building a program which is machine-transpiled C code. It >>>>> should be valid C with no errors. (If there are, that is the >>>>> responsibility of the transpiler author.) But again you don't care >>>>> about style, or the fact that there are lots of unused labels for >>>>> example (common in such code) >>>> >>>> Then >>>> >>>> * you still want linting in the source language. >>> >>> Possibly. I don't care too much about that either. In my stuff, I do >>> very little in the way of advisory reports, which are only enabled >>> infrequently. >>> >>> But the context here is using linting to warn about things that are a >>> consequence of C's design, such as switch 'break' that is the subject >>> of the thread. >>> >>> I prefer to deal with that with a better language design. >> >> Are you making a "new" C?[...] > > I'm not making anything. Why go after C... Make something better? > > I have long maintained a personal systems language which fixes most of > my moans about C (and even deals with some of fir's needs, but those > seem to change erratically). > > It would have been good for /someone else/ to have evolved C in a > direction I'd have found useful, but current evolvement of C is not > interesting to me and IMO misguided. > > Since I have my own solutions for the little coding I do now, this > doesn't matter so much - let C aficionados be masochists if they want. > > But I am still interested in tooling (which has its own masochists!).
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads