HN user

begriffs

3,039 karma
Posts132
Comments144
View on HN
begriffs.com 2y ago

How to build dependable bare-metal ARM firmware with Unix tools

begriffs
1pts1
news.ycombinator.com 3y ago

Ask HN: How to protect blog from AI search?

begriffs
4pts1
begriffs.com 5y ago

Dynamic Linking Best Practices

begriffs
134pts10
begriffs.com 5y ago

Dynamic Linking Best Practices

begriffs
4pts0
begriffs.com 5y ago

Tips for stable and portable software

begriffs
84pts63
begriffs.com 5y ago

How to write programs that won't break in a year

begriffs
3pts0
begriffs.com 5y ago

Tips for Stable and Portable Software

begriffs
1pts0
begriffs.com 6y ago

Show HN: multipart MIME email that looks great everywhere

begriffs
3pts0
begriffs.com 6y ago

Generating multipart MIME email from markdown

begriffs
3pts0
begriffs.com 6y ago

Show HN: Impeccable MIME Email from Markdown

begriffs
2pts0
begriffs.com 6y ago

Concurrent Programming, with Examples

begriffs
330pts88
news.ycombinator.com 6y ago

Ask HN: As a programmer, how to help medicine?

begriffs
2pts1
nickdrozd.github.io 6y ago

The most evil Lisp macro

begriffs
3pts0
begriffs.com 7y ago

History and Effective Use of Vim

begriffs
593pts218
begriffs.com 7y ago

History and Effective Use of Vim

begriffs
2pts0
begriffs.com 7y ago

Unicode Programming in Depth

begriffs
1pts0
begriffs.com 7y ago

How Unicode Works (With Examples)

begriffs
3pts0
begriffs.com 7y ago

Unicode Programming, with Examples

begriffs
1pts0
github.com 7y ago

Trusting Unicode strings like SSH fingerprints

begriffs
2pts0
github.com 7y ago

Show HN: Unicode Trust on First Use

begriffs
6pts0
begriffs.com 7y ago

Show HN: Git via FTP Interface

begriffs
3pts0
begriffs.com 7y ago

Show HN: Browsing a Remote Git Repo

begriffs
9pts1
github.com 7y ago

Demo of using Haskell in a C project

begriffs
3pts0
begriffs.com 7y ago

C Portability Lessons from Weird Machines

begriffs
270pts117
begriffs.com 7y ago

Actually, DMARC works fine with mailing lists

begriffs
1pts0
begriffs.com 8y ago

Ultimate Guide to PostgreSQL Constraints

begriffs
2pts2
begriffs.com 8y ago

PostgreSQL Domain Integrity in Depth

begriffs
5pts0
begriffs.com 8y ago

Deferrable SQL Constraints in Depth

begriffs
5pts0
begriffs.com 9y ago

The Design and Use of QuickCheck

begriffs
147pts36
begriffs.com 9y ago

Hardcore Linux Workstation Guide

begriffs
4pts0

I have a hard-copy of this book, and it seems like the PDF isn't the final version, judging by the hand drawn illustrations at least.

The book does dive into some old and arcane object file formats, but that's interesting in its own way. Nice to get a comparison of how different systems did things.

After reading that book and other sources, I examined how people typically create libraries in the UNIX/Linux world. Some of the common practices seem to be lacking, so I wrote an article about how they might be improved: https://begriffs.com/posts/2021-07-04-shared-libraries.html

Edit: That covers the dynamic linking side of things at least.

Interesting, maybe it depends on the reader. I tried a channel just now in newsboat and it wasn't smart enough to find the feed, even though I see the page contains

    <link rel="alternate" type="application/rss+xml" title="RSS" href="...">

Oh yeah, gotta love the secret feed link.

    https://www.youtube.com/feeds/videos.xml?channel_id=$FOO
I follow a number of channels this way. I'm grateful and sort of surprised YouTube hasn't killed it off.
Debugging with GDB 4 years ago

Good idea to just abort it. :)

However, I tried your suggestion from another terminal, and gdb appears to shield the program somehow. What ended up working is running "signal SIGABRT" from within gdb.

One thing that's still lacking is gcore's ability to take a snapshot of the core without killing the program. "Unlike after a crash, after gcore finishes its job the program remains running without any change." https://www.man7.org/linux/man-pages/man1/gcore.1.html

Debugging with GDB 4 years ago

OpenBSD, where you get core files by default

By this, are you referring to the behavior: "By default, this memory image is written to a file named programname.core in the working directory, provided the terminated process had write permission in the directory[...]" (from https://man.openbsd.org/core.5) ?

Also, do you know if there's a way to obtain a core file from a running process on OpenBSD? I don't see a port of gcore, and (e)gdb on OpenBSD doesn't support the generate-core-file command (it says, "Can't create a corefile").

Well that was certainly a lot of fluff and FUD.

OP says:

Look at your program's CPU usage. If the sum of your threads is <100% of one core, then there is no reason whatsoever for you to use threads.

Attacking a CPU-bound problem with parallelism is only one reason for using threads. Concurrency (even on one processor) has benefits.

The shame is in believing ourselves super-human, and reaching for a tool that we don't need, in full knowledge that we're likely to shoot ourselves in the foot with it.

Although synchronization primitives require care, they're not that hard. You don't need super-human powers.

I took some time to understand pthreads and apply them to example programs. For a careful and balanced overview, see my article:

https://begriffs.com/posts/2020-03-23-concurrent-programming...

As you mention, the fundamental integer types have guaranteed minimum sizes (or pedantically a range that matches the following sizes if twos' complement is used):

* >=8 bits: char (CHAR_BIT is exactly 8 in POSIX)

* >=16 bits: short and int

* >=32 bits: long

* >=64 bits: long long

The C99 typedefs like uint16_t have to be chosen internally to be one of the underlying types. For those sizes that have no matching underlying type, the implementation will omit typedefs.

However don't forget the more flexible C99 typedefs int_leastN_t and int_fastN_t. They both will give you a type of at least N bits, where the "fast" one chooses whichever type is most convenient for the processor, and the "least" version picks whichever is smallest. (For instance int_least16_t is probably short, and int_fast16_t is probably int.)

Has there been a survey to determine what percentage of known compilers support each C version, like C89, C99, C11? I've been sticking to C99 because I assumed later versions won't be widely adopted for a long time to come. Is this accurate?

Would the following be a correct way to determine whether there's a problem?

* First call setlocale(LC_CTYPE, "en_US.UTF-8")

* Next feed the UTF-8 string representation of every Unicode codepoint one at a time to mbstowcs() and ensure that the output for each is a wchar_t string of length one

* If all input codepoints numerically match the output wchar_t UTF-32 code units, then the implementation is officially good, and should define __STDC_ISO_10646__?

What does the presence or absence of __STDC_ISO_10646__ indicate exactly? I found this part of the C99 spec obscure.

For instance, the macOS clang environment does not define this symbol. Is their implementation of wchar_t or <wctype.h> lacking some aspect of Unicode support?

It's hard to beat this list of quality books:

http://iso-9899.info/wiki/Books#Learning_C

Read some and do the exercises. You'll learn to write portable code to a standard rather than stuff that "accidentally works." There's a lot of crap C code in the world, full of GNUisms, overzealous macros, header-only nonsense abusing translation units, and copypasta. Don't pick up bad habits from that stuff.

OP has an extravagant threat model. Yeah if I were trying to hide communications from some dictator where even the metadata of recipient and timestamp is damning then of course email is out.

PGP is a good way to communicate under the right circumstances. Say I'm writing to someone I trust and have verified their key fingerprint via a secure channel (in person, over the phone, etc). If I were sending them login credentials for a shared site, or bank info for setting up a payment, or even just wanted to block general corporate snooping then what's wrong with PGP? It's "pretty good privacy."

It's nice that I can apply the cryptography on a local machine and then send the result over email. I don't need to sign up for the paranoid chat app du jour.

( In fact PGP is useful for more than signing/encrypting mail, see https://begriffs.com/posts/2016-11-05-advanced-intro-gnupg.h... )

Broken 7 years ago

Although I use a mac for work, I have a spare thinkpad with openbsd, which I think of as my "forever system." I put stable software on it and generally go with the OS defaults. Over time I patiently refine the configuration files, adding a little polish here and there. The experience keeps improving, and perhaps some day it will be my main system, and work completely smoothly.

IMHO investing time to get too comfortable with the changing mac ecosystem is ultimately wasted work since it will eventually change/break.

If your buffer isn't a NUL-terminated, then don't call a function that is only defined for NUL-terminated buffers.

It's not that people want to pass strncpy source buffers that lack NUL termination, it's that strncpy in certain situations will not NUL terminate its results.

https://begriffs.com/posts/2019-01-19-inside-c-standard-lib....

some people claim strlcpy() is 'broken'

Speaking of strlcpy, it thankfully doesn't have the problem that strncpy does. However strlcpy is not in the C standard or in POSIX, so can't be used portably. In C99 snprintf is a better choice.

the same expression broke on a lot of compilers as soon as optimization was turned on

C is not a "try it and see" language. If you stray from the spec then things will act differently and break between compilers. Section 7.13.2 specifies that only local variables declared as volatile will have a determinate value after a longjmp.