bart <bc@freeuk.com> writes:
[...]
I'm trying to stand up for myself as I'M AT THE END OF MY FUCKING[...]
TETHER HERE.
ALL YOU PEOPLE WANT TO DO IS JUST TRASH EVERYTHING I'VE DONE.
EVERY SINGLE THING I SAY IS WRONG. NOTHING I SAY IS EVER
RIGHT. WHATEVER IT IS I SAY, YOU SAY THE OPPOSITE THING.
MY SELF-ESTEEM HAS NEVER BEEN LOWER - YOU HAVE DESTROYED ME.
Bart, if this is sincere, please consider stepping away from
comp.lang.c for a while. I have no motivation for this post other
than concern for your well-being.
What do you think of this control block?
do
{
FILE f = fopen("file.txt", "r");
if (f == NULL) quit; /*goes to else part*/
/*success here*/
for (int i =0; i < 10; i++){
...
if (error) quit;
}
}
else
{
/*some error*/
}
Thiago Adams:
What do you think of this control block?
do
{
FILE f = fopen("file.txt", "r");
if (f == NULL) quit; /*goes to else part*/
/*success here*/
for (int i =0; i < 10; i++){
...
if (error) quit;
}
}
else
{
/*some error*/
}
I have come to the conclusion that lots of advanced and very
speficic control-flow structures are being invented to avoid
using `goto' -- a simple and generic solution, with the
additoinal bonus of keeping the semantically linear code
actually flat.
Your proposal is not bad: it is keeping the main code flat
and saves extracting the `do' part into a separate function
(to take advantage of `return`). The `else' keyword seems
misleading, because it is not strictly alternative to the
`do' part. Is it your purpose to re-use C's existing
keywords? If not, then consider `fail` instead of `quit`
and `onfail` instead of `else`. Also, `do' may be renamed
`failable', indicating a block with controlled failure.
P.S.: I am eternally unhappy with the control-flow mechanisms
in existing programming languages.
On 10/8/2025 8:14 AM, Anton Shepelev wrote:
I have come to the conclusion that lots of advanced and very
speficic control-flow structures are being invented to avoid
using `goto' -- a simple and generic solution, with the
additoinal bonus of keeping the semantically linear code
actually flat.
The problem with goto is define a name and to find this name
on the source code. Is it up or down?
[...]--- Synchronet 3.21a-Linux NewsLink 1.2
[...]
P.S.: I am eternally unhappy with the control-flow mechanisms
in existing programming languages.
The problems with 'goto' go even farther than only the
technical lookup; it goes into the semantical domain when
jumping into and out of scopes (for example).
Janis Papanagnou:
The problems with 'goto' go even farther than only the
technical lookup; it goes into the semantical domain when
jumping into and out of scopes (for example).
All true. I almost never use upwards-going goto (except for loop-and-a-half), and I never jump inside scopes, only out
of them.
Alternatives:
try {
throw; //error
quit; //early success - exit without going to catch
}
catch {
}
What do you think of this control block?
do
{
FILE f = fopen("file.txt", "r");
if (f == NULL) quit; /*goes to else part*/
/*success here*/
for (int i =0; i < 10; i++){
...
if (error) quit;
}
}
else
{
/*some error*/
}
No RAII ? Silly language !
Em 15/10/2025 18:04, Bonita Montero escreveu:
No RAII ? Silly language !
I would be happy to chat about the disadvantages of RAII.
I think this is for another topic, and someone could complain
that is not about C. I think it is about C, why not introduce
RAII in C.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,073 |
Nodes: | 10 (0 / 10) |
Uptime: | 222:34:57 |
Calls: | 13,783 |
Calls today: | 1 |
Files: | 186,987 |
D/L today: |
702 files (242M bytes) |
Messages: | 2,434,871 |