HN user

notpopcorn

184 karma
Posts2
Comments8
View on HN

If you take a screenshot of it, the effect is gone. The emoji and the background are just the same #ffffff in the screenshot. Seems like an easy way to make some unscreenshottable text or something. I don't know how I feel about that.

Another example of a very hidden feature is "export/print as pdf". If you do share => print, you don't get a pdf option, but you can do a zoom gesture on the preview and then +poof+, it's a pdf you can save. How was I supposed to discover that?

Rust 1.63 4 years ago

A const is like a `#define` in C or C++, while a static is a global variable.

So we use a &'static str here instead of a C string so there are some changes to the C code.

[..]

So why does this type not support zero initialization? What do we have to change? Can zeroed not be used at all? Some of you might think that the answer is #[repr(C)] on the struct to force a C layout but that won't solve the problem.

The type of the first field was switched to a type (&str) that specifically promises it is never null. If the original type (a pointer) was kept, or a Option<&str> was used, mem::zero would've worked fine.

Without any unsafe code this is simply:

    let role = Role {
        name: "basic",
        flag: 1,
        disabled: false,
    };
The language tries to prevent you from interacting with a `Role` object that's not fully initialized. `mem::zero()` could work, but then you'll have to turn the `&'static str` into an `Option<&'static str>` or a raw pointer, to indicate that it might be null. You could also add `#[derive(Default)]` to the struct, to automatically get a `Role::default()` function to create a `Role` with and then modify the fields afterwards, if you want to set the fields in separate statements for some reason:
    let mut role = Role::default();
    role.name = "basic";
    role.flag = 1;
    role.disabled = false;
And even with `MaybeUninit` you can initialize the whole struct (without `unsafe`!) with `MaybeUninit::write`. It's just that partially initializing something is hard to get right, which is the point of the article I guess. But I wonder how commonly you would really want that, as it easily leads to mistakes.

MAX_THREAD_IDS is defined as 128 in a file with a copyright notice of 2005, which was when the very first consumer dual core processors started getting released:

https://github.com/perilouswithadollarsign/cstrike15_src/blo...

Entirely reasonable that no one in 2005 would even consider the possibility of 128 core processors. I bet nobody reconsidered or even looked at that code ever since, until it started breaking because of today's extremely parallel cpus starting to get somewhat affordable for consumers.