HNHacker News
TopNewBestAskShowJobs

_kst_

2,297 karma · joined March 20, 2012

Keith.S.Thompson+hn@gmail.com
submissionscomments
_kst_··on The perils of transition to 64-bit time_t
Code that assumes time_t is the same width as int is already broken, and won't work on typical 64-bit systems were int is 32 bits and time_t is 64 bits.

In any case, I'm not sure I've ever seen any such code.

_kst_··on Lesser known tricks, quirks and features of C
See my comment above:

https://news.ycombinator.com/item?id=41664474

_kst_··on Lesser known tricks, quirks and features of C
A compiler can reuse memory as much as it likes -- but only if the visible behavior of the program is consistent with the language requirements.

If you write:

    {
        int n = 42;
        printf("%d\n", n);
    }
in the abstract machine, `sizeof (int)` bytes are allocated on entry to the block and deallocated on exit, but a compiler can legally replace the entire block with `puts("42")` and not allocate any memory for `n`.

Memory for objects defined in nested blocks is logically allocated on entry to the block, but compilers commonly merge the allocation into the function entry code. Even so, objects in parallel blocks can certainly share memory:

    int main(void) {
        {
            int a;
        }
        {
            int b; // might share memory with a
        }
    }
Logically, memory for `a` is allocated on entry to the first inner block, and memory for `b` on entry to the second inner block. Compilers will typically allocate all the memory on entry to `main`, but can use the same address for `a` and `b`.
_kst_··on Lesser known tricks, quirks and features of C
It returns 2.

The only reason that might be surprising is that the "return *p;" statement refers to the value of an object at a point (textually) before its definition. But the lifetime of the object named "v" begins on entry to the innermost compound statement enclosing its definition -- in this case the body of "main".

Space for "v" is allocated on entry to "main". It's initialized to 1 when its definition is reached. The "return *p;" statement appears before the definition of "v" in the program source, but is executed after its definition was reached at run time, and within its lifetime.

It's important to remember that scope and lifetime are two different things. The scope of an identifier is the region of program text in which the identifier is visible; for "v" it extends from the definition to the closing "}". The lifetime of an object is the time span during execution in which it exists; for "v" it extends from the time when execution reaches the opening "{" to the time when execution reaches the closing "}". Formally, storage for "n" is allocated at the beginning of its lifetime and deallocated at the end of its lifetime. Compilers can and do optimize allocation and deallocation, as long as the visible behavior is consistent.

Aside: If "v" were a VLA (variable length array, introduced in C99, made optional in C11) its lifetime would begin when execution reaches its definition.

_kst_··on Lesser known tricks, quirks and features of C
Background: A %n format specifier in a printf call stores the number of characters written so far into a specified variable. For example:

    #include <stdio.h>
    int main(void) {
        int count;
        printf("%s%n\n", "hello, world", &count);
        printf("count = %d\n", count);
    }
The output is:

    hello, world
    count = 12
%n can be exploited to write data to an arbitrary memory location, but only if the format string is something other than a string literal.

%n can be exploited, but it's entirely possible to use it safely.

_kst_··on Comic Mono
I tried it in PuTTY on Windows.

I ran into two problems.

1. Poor coverage of non-ASCII characters (it won't display simple accented letters, pound sign, euro sign, etc.).

2. []{} are cut off at the top.

_kst_··on Command-Line Utility to Backup Google Mail, Calendar and Contacts to Files
I had a similar problem. I've submitted an issue.

https://github.com/WeeJeWel/node-google-backup/issues/1

_kst_··on I'm not a fan of strlcpy(3)
I just discovered that typing man 'printf(1)' or man 'printf(3)' actually works (at least with the man command on Ubuntu, provided by the "man-db" package).

You have to quote or escape the parentheses because they're shell metacharacters, which IMHO makes that syntax more trouble than it's worth.

Other commands that work are "man 3 printf", "man -s 3 printf", and "man printf.3". I think "man 3 printf" is the oldest version.

At least one other version of the man command (NetBSD) doesn't accept "man printf.3" or "man 'printf(3)'".

_kst_··on Entering text in the terminal is complicated
To be clear, it's not the terminal emulator (xterm, mintty, iTerm2, etc.) that does this. It's the tty layer. You can use the stty command to change the settings.
_kst_··on Show HN: Shpool, a Lightweight Tmux Alternative
For the second, <git://git.subdivi.de/~helmut/tcvt.git> might be useful. It's not quite what you asked for; it emulates a two-column virtual terminal within another (virtual) terminal.

If you can extend your terminal window across your two monitors and run `tcvt` within it, that might suit your purposes.

_kst_··on Safe Terminal Escape Codes
> emulating a vt340+ like xterm does gives you the first six of these, which is a big reason why people keep writing new programs for that platform, but totally flunks the last one; you can't even display text in a proportional font, much less a photo or a video

xterm supports sixel graphics.

"sixel" is an image file format; the ImageMagic "convert" command can convert other formats to it. Just cat a sixel file to stdout in an xterm and it's displayed in the window.

The implementation is not 100% solid (for example, there's a size limit), but it does work. And tmux can be build with sixel support, so you can display sixel images in tmux under xterm.

    convert foo.png sixel:-
or

    convert -geometry 600x600 large.png sixel:-
https://en.wikipedia.org/wiki/Sixel

No, there's no video support (unless I've missed something).

_kst_··on Orthodox C++
Except that in C (at least prior to C23), it should be "int main(void)".

I'm fairly sure that all existing C compilers will quietly accept "int main()", but there's an argument that "int main()" causes the program to have undefined behavior. "int main(void)" is the form documented in the standard.

And the "return 0;" is unnecessary both in C++ and in all versions of C starting with C99. (Some will argue that it's better style to be explicit.)

These are admittedly minor points.

_kst_··on Show HN: Comma Separated Values (CSV) to Unicode Separated Values (USV)
https://www.databricks.com/glossary/what-is-parquet

(I don't think everyone has moved to it. I had never heard of it myself.)

_kst_··on Show HN: Vlite – Lite demo server, inspired by Vite
In addition to a sentence about what this solves relative to Vite, another sentence saying what Vite is would also be helpful to those of us who have never heard of Vite. A link to https://vitejs.dev/ would probably suffice, though even that site doesn't seem to explain much until you follow some links.

I'm very probably not the target audience for this, but the README should have enough information to tell me I'm not the target audience.

(From that site: "Vite (French word for "quick", pronounced /vit/, like "veet") is a build tool that aims to provide a faster and leaner development experience for modern web projects.")

_kst_··on Useful Uses of cat
No, the command is

    < x Y | Z > w
where x and w are files, not commands.

Something that "cat file | ..." advocates might be overlooking is that a redirection ("<inputfile", ">outputfile", "2>errorfile") can appear anywhere within a simple command, so these:

    command -option < file
    < file command -option
    command < file -option
are all exactly the same -- and of course very similar to

    cat file | command -option
If the purpose of typing "cat file | command" is to put the input file at the beginning (which does make logical sense), you can achieve the same thing with "< file command". Admittedly, it does look at bit strange if you're not accustomed to it. (It even works with csh and tcsh.)
_kst_··on Porting to GCC 14: C language issues
I think there are two reasons int has not gone from 32 to 64 bits on 64-bit systems.

Part of it is backward compatibility: code written to assume 32-bit int could break. (Arguably such code is badly written, but breaking it would still be inconvenient.)

Another part is that C has a limited number of predefined integer types; char, short, int, long, long long (plus unsigned variants and signed char). If char is 8 bits and int is 64 bits, then you can't have both a 16-bit and a 32-bit integer type. Extended integer types (introduced in C99) could address this, but I don't know of any compilers that provide them.

_kst_··on Stories removed from the Hacker News Front Page, updated in real time
Or include the URL rather than just the HN ID so readers can follow the links.
_kst_··on Arno A. Penzias, 90, Dies; Nobel Physicist Confirmed Big Bang Theory
https://www.youtube.com/watch?v=5rVBu6i6Qwk
_kst_··on C23: A Slightly Better C
https://www.c-faq.com/ question 10.4

"What's the best way to write a multi-statement macro?"

_kst_··on Bug story: Sorting by timestamp
That should only matter if times are stored and sorted as local time. Storing time as UTC (e.g. seconds since 1970) and computing local time from that and the current time zone should avoid DST-related bugs.
_kst_··on I Hate MFA
Blowing my own horn a little, I have a Perl script that generates random passwords, with options to, for example, generate a 16-character password with lowercase letters, but with one uppercase letter, one digit, and one punctuation mark, all chosen randomly and placed at a random position:

    $ gen-password -len 16 -lower -1upper -1digit -1punct
    e$hmvcel9nyghAyw
Another script in the same project generates XKCD-style random passphrases.

https://github.com/Keith-S-Thompson/random-passwords

_kst_··on B.C. looks to standardize multiplex designs as latest fix to housing crisis
I suggest updating the title to say "British Columbia". (I thought it might be Baja California.)
_kst_··on The Unix timestamp will begin with 17 this Tuesday
Timestamp 1000000000 (Sat 2001-09-08 18:46:40 PDT) triggered a bug in the bug reporting system (Remedy) we were using at the time.

The system stored timestamps as a string representing seconds since the epoch, but it assumed it would fit in 9 digits. At 1000000000, it started dropping the last digit, so it went back to Sat 1973-03-03 01:46:40 PST, advancing at 10% of real time. It was fixed fairly quickly.

_kst_··on Yup, that was an earthquake outside SF
Looks like the epicenter was 13.1 kilometers directly below SFO (San Francisco International Airport, which is south of San Francisco).

Updated magnitude is 3.7.

_kst_··on *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
A clarification: You can certainly assume that char is 8 bits if you don't mind losing portability to a small minority of systems.

If I'm being pedantic, I might add something like

    #if CHAR_BIT != 8
    #error "This code assumes 8-bit char"
    #endif
But realistically, if I'm using headers defined by either POSIX or Windows, that's probably enough of a guarantee. (Though I'd still use CHAR_BIT rather than 8 to refer to the number of bits in a byte.)
_kst_··on *(char*)0 = 0; – What does the C++ programmer intend with this code? [video]
You can't assume char is one octet. It is one byte by definition.

A byte is CHAR_BIT bits, where CHAR_BIT >= 8. (It's exactly 8 on most implementations; DSPs are the most common exception).

short and int are both required to be at least 16 bits wide. It's possible for int to be 1 byte (sizeof (int) == 1), but only if CHAR_BIT >= 16.

_kst_··on Ask HN: Who is hiring? (October 2023)
"LA" is Los Angeles, CA (could also have been Louisiana)
_kst_··on A new era for Arecibo
The Arecibo dish was not steerable, so there are large parts of the sky that it couldn't see.

China built a similar radio telescope that went into service in 2016. https://en.wikipedia.org/wiki/Five-hundred-meter_Aperture_Sp...

_kst_··on Tell HN: Please don't print –-help to stderr in your CLI tools
"But agreed that an explicit --help should print to stderr."

I think you meant stdout here, not stderr.

_kst_··on Tell HN: Please don't print –-help to stderr in your CLI tools
I think the suggestion was not that the tool should page the output, but that the user can easily do so:

    tool [args] 2>&1 | less
Presumably "less" knows how big your terminal is.
← PreviousPage 3 of 23Next →