Earlier quoted context omitted.
Sorry, I'm not following. Introduction section of what?
The C programming language by Kernighan and Ritchie, the very source of hello world.
Bugs in Hello World
251–260 of 262 posts
Re: Bugs in Hello World
#252Earlier quoted context omitted.
There is a difference between a program with a specification/documentation outlining what it should do, and one that doesn't have a spec. AFAIK, hello.c doesn't have a spec, so the code is the spec. If I am using it, I have to read the code to know what it does.
So if I don't write a spec, I have no bugs. Got it.
I said if a software doesn't have a spec, the code IS the spec.
If I hand out a sheet of paper saying "the program returns X", but running it returns Y instead, the program is buggy.
If I hand out a piece of code which says "return X", and someone runs it expecting it to return Y, thats not the codes problem.
Re: Bugs in Hello World
#253Earlier quoted context omitted.
Well, Java has since introduced RuntimeIOException, which could be used in cases where an IO exception is unexpected, so we could introduce a new class, say, ErrorCheckingPrintStream, and add the method `ErrorCheckingPrintStream withErrorChecks()` to PrintStream if it's considered sufficiently worthwhile. So you could have: System.out.withErrorChecks().println("Hello World!); But we can't change the behaviour of the…
I think you mean UncheckedIOException - https://docs.oracle.com/javase/8/docs/api/java/io/UncheckedI... RuntimeIOException from Jira has an amusing (and incorrect, IMO) message: https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/... > An IOException was encountered and the stupid programmer didn't know > how to recover, so this got thrown instead. It's a misguided doc comment because "recovering" from error…
Re: Bugs in Hello World
#254Earlier quoted context omitted.
So if I don't write a spec, I have no bugs. Got it.
This Porsche has a design flaw: I can only go 22,500 kilometers before I have to replace the tires. This VW bus has a design flaw: I can't pull more than 1G on the race track.
Re: Bugs in Hello World
#255Earlier quoted context omitted.
I'm actually really curious about this setup. Can you go into a bit more detail about how it works ?
I run Firefox inside a systemd-nspawn[0] container. I wrote a little wrapper around systemd-nspawn that I call arch-lwc[1] which kinda mimics the docker CLI. I have another script to coordinate the Firefox-specific stuff. [0]: https://wiki.archlinux.org/title/Systemd-nspawn [1]: https://github.com/b0o/arch-lwc
Re: Bugs in Hello World
#256Earlier quoted context omitted.
I work as a sysadmin and only write the odd program/script (Python, Perl, Bash). In the past, I’ve run into the problem of not being able to write to a log file (disk full or insufficient permissions) so I now check for these situations when opening or writing to a file. A while ago, I started learning C in my personal time and am curious about this issue. If `close()` fails, I’m guessing there’s not much else the pr…
For both close() and fsync() it depends on how they fail. You should generally call them in a loop and retry as long as they're returning an error that's EINTR. I.e. to retry past signal interruptions. This is really more about POSIX and FS semantics than C (although ultimately you end up using the C ABI or kernel system calls, which are closer to C than e.g. Python). POSIX gives implementations enough leeway to have…
Re: Bugs in Hello World
#257I couldn't see GNU Hello mentioned in the article or comments so far. I wonder how it fares bug-wise. The GNU Hello program produces a familiar, friendly greeting. Yes, this is another implementation of the classic program that prints “Hello, world!” when you run it. However, unlike the minimal version often seen, GNU Hello processes its argument list to modify its behavior, supports greetings in many languages, and…
This is explicitly called out and handled in lines 151-155. https://git.savannah.gnu.org/cgit/hello.git/tree/src/hello.c Here's the comment: /* Even exiting has subtleties. On exit, if any writes failed, change the exit status. The /dev/full device on GNU/Linux can be used for testing; for instance, hello >/dev/full should exit unsuccessfully. This is implemented in the Gnulib module "closeout". */
Re: Bugs in Hello World
#258Earlier quoted context omitted.
> not that the command returned 0 but that the file it made exists and is the right length If a command returns 0 when it didn't really do its job. Shouldn't we fix the command instead of the script?
See the link for examples of bash and posix internals that don’t necessarily operate the way you’d expect.
Re: Bugs in Hello World
#259Earlier quoted context omitted.
None. Hello world is a program for beginners to teach them the most basic way to debug a program. The sole purpose of hello world is to explain how to print internal state of a program. In that case the examples are correct, they succeed.
I think a lot of people are getting too hung up on the fact that the application is specifically "hello world." The code is clearly buggy, even if you don't particularly care about bugs in this specific application. The author would have been better off not mentioning "hello world" as the application and simply said: Find the bug! puts("This is a log"); I think everyone can agree that the above should be considered a…
Re: Bugs in Hello World
#260Earlier quoted context omitted.
For didactic reasons it’s preferable to consider it a bug.
hello.c is meant as the first program a new student encounters when learning C. At that point, the student has enough to worry about; writing code to a file, checking for syntactic errors, basic program structure, using the compiler, executing the binary, understanding what `#include ` means,... Sure, we could update it: // hello_v2.0.c #include #include #include int main(void) { printf("Hello, World!\n"); fflush(std…
Compare this with Rust, where the usual hello world will just do the right thing:
$ cat > a.rs
fn main() {
println!("Hello World");
}
$ rustc a.rs
$ ./a
Hello World
$ echo $?
0
$ ./a > /dev/full
thread 'main' panicked at 'failed printing to stdout: No space left on device (os error 28)', library/std/src/io/stdio.rs:1187:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ echo $?
101