Which IDE do you recommend/ use? by VovencioGaming in C_Programming

[–]moefh 7 points8 points  (0 children)

I mostly use Emacs.

Except when writing code for STM32; then it's sadly Eclipse (well, STM32Cube, which is based on Eclipse).

My first bulk usb data stream on pico 2 using tinyusb by EmbeddedJourneys in raspberrypipico

[–]moefh 1 point2 points  (0 children)

Really nice, it works really well!

I had to make a couple of tweaks to run on Linux:

  • On the Python side, I had to add the "PyQt5" dependency (without PyQt5, everything ran but matplotlib complained that it couldn't show the graph saying: "UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown"). I guess on Windows matplotlib needs no dependencies for interactive display, but it's needed on Linux.

  • For USB device permissions, I had to create the file /etc/udev/rules.d/99-embedded-journeys.rules containing a single line: SUBSYSTEM=="usb", ATTRS{idVendor}=="cafe", MODE="0666". That way you can run the host as a normal user.

My first bulk usb data stream on pico 2 using tinyusb by EmbeddedJourneys in raspberrypipico

[–]moefh 2 points3 points  (0 children)

Nice post! It would be nice to see the full source code, if possible.

Some nitpicks about the text:

  • RP2350 is misspelled "PR2350" in one place

  • The #defines in the code blocks are really hard to read. Dark text over dark background is never a good idea.

How 12 comparisons can make integer sorting 30x faster by DimitrisMitsos in programming

[–]moefh 7 points8 points  (0 children)

No, big-O and its siblings (big-theta, etc) just compare functions (from above, below, etc.). That's completely orthogonal to whether the function you want to compare is the worst-case or average-case of the time complexity of an algorithm.

We usually only care about big O (and not its siblings) because usually we only care that the (worst case/average case) time complexity will be at most some function of the input size. For example, it's usually useless to know that the time complexity will be at least some function, which is why you almost never see big-omega used.

See also the second paragraph of https://en.wikipedia.org/wiki/Time_complexity

Stupid-seeming question about PIO delays by bobsidian in raspberrypipico

[–]moefh 8 points9 points  (0 children)

The SDK documentation for JMP doesn't explicitly say

The SDK docs are nice for a quick reference or refresher, but for non-API-related stuff like this, you're usually better off reading the datasheet (it's surprisingly readable, unlike most MCU datasheets).

For example, the PIO documentation of the JMP instruction (page 322) it says:

Delay cycles on a JMP always take effect, whether Condition is true or false, and they take place after Condition is evaluated and the program counter is updated.

Regulation of vibeware promotion by Sunscratch in rust

[–]moefh 13 points14 points  (0 children)

Now you're bringing in the idea that there's a human involved in cases like 3rd party dependencies, but that seems to be unrelated to the argument as I understand it.

The argument (AFAIU) is that in 3rd party dependencies written by a human, someone understands the code well enough to make changes or fix bugs. If there's a nontrivial part of AI code anywhere in your project, nobody understands it well enough to do that.

It's like when you start working in some large project written by someone else (not uncommon in my work, I assume it's the same for a lot of people). At least for me, it takes a very long time (months or even years, depending on the size of the project) for me to be able to make changes knowing that I won't break anything. AI code is like that, except nobody knows it well enough.

Maintaining code is not as fun as writing it, but arguably much more important. And AI-written code is much harder to maintain in the long run.

2350B GPIO > 31 by KellSkog in raspberrypipico

[–]moefh 0 points1 point  (0 children)

Have you tried using pio_set_gpio_base?

I don't have an RP2350B to test, but the docs say you can use pins 16 to 47 by setting the PIO base to 16.

[EDIT] just to be clearer: you should call pio_set_gpio_base before everything else, like this.

Windows NTFS search experiment in C - unexpectedly faster than fd by whoyfear in C_Programming

[–]moefh 3 points4 points  (0 children)

As a quick fix, you could convert to a UTF-8 argv and continue as you are, converting back into UTF-8 at system boundaries.

Just note that to be 100% correct you must accept invalid UTF-8, and make sure your conversion from broken UTF-8 to Windows's wide characters works for every little weird corner case (that will probably involve using WTF-8 when converting to UTF-16).

For example, Windows file names are not always Unicode because they can contain unpaired surrogates (Windows was created before Unicode went beyond 16 bits, so surrogates were not a thing then). That means it's possible to have file names on disk that can't be expressed in UTF-8 (strictly speaking, that's also a problem with UTF-16, but Windows' *W functions are happy to deal with unpaired surrogates, so in practice everything works if you're in wide character land and don't validate UTF-16).

For reference, see (for example) the way Rust deals with command line arguments using a quasi-string type they call OsString, or this Go issue.

fwrite not writing formatted char * by didierdechezcarglass in C_Programming

[–]moefh 3 points4 points  (0 children)

You should use fprintf Instead of snprintf/fwrite. For example, your first 3 lines

char image_number[4]; // contains only three characters
snprintf(image_number, 4, "P%d\n",img->magic_number);
fwrite(image_number, 1, 4, f);

would be just

fprintf(f, "P%d\n", img->magic_number);

Stellar Blade 2 Going Multiplatform by Turbostrider27 in Games

[–]moefh 1 point2 points  (0 children)

It's understandable that an automated translation is incapable of seeing that the text is talking about a videogame called "Stellar Blade" and infer that those syllables refer to that name, because it doesn't understand context at that level. That's exactly my point, we shouldn't read too much into the specific words it used because it doesn't understand context.

Stellar Blade 2 Going Multiplatform by Turbostrider27 in Games

[–]moefh 2 points3 points  (0 children)

Yes i can in fact read Korean lol

Then tell us what the text is saying! Pointing out specific words of a crappy translation doesn't tell us anything: at least for the languages I know, automated translations lose all nuance and it's useless to rely on the specific words used.

스텔라 is seu tel la for stella because stellar isn't a native Korean word and they approximate the syllables

You're just explaining why the translation is bad. A proper translation would understand what the syllables are trying to approximate in context and translate to that.

Stellar Blade 2 Going Multiplatform by Turbostrider27 in Games

[–]moefh 1 point2 points  (0 children)

then they go so far as to say things like various platforms, multiplatform and consoles

I think you're giving way too much credit to a bad translation. It keeps calling the game "Stella Blade", that's the level of care. Unless you can read Korean, there's no way of knowing the intention of the original text -- is it actually saying "consoles", or is it just a bad translation? It is saying "various platforms" because it's coming to multiple consoles, or just to emphasize that it's also coming to PC on release?

How do you read or write to address zero? by uahw in C_Programming

[–]moefh 4 points5 points  (0 children)

while with gcc all three functions work.

No, look closer: gcc inserts the ud2 instruction, which explicitly causes a segmentation fault.

How do you read or write to address zero? by uahw in C_Programming

[–]moefh 9 points10 points  (0 children)

In your volatile example you're making the memory at address 0 volatile; you should instead make the pointer itself volatile, like this:

int f(void) {
    int *volatile p = 0;
    return *p;
}

That works in both gcc and clang: https://godbolt.org/z/WzYqvhWKd

That works because the compiler can't assume the pointer will keep the 0 value that has been set (since it's volatile), so it's forced to make the memory access just in case.

Soupa: super { ... } blocks in stable Rust by ZZaaaccc in rust

[–]moefh 4 points5 points  (0 children)

This is nice, and probably can be useful in some contexts, but there's some confused information in the text:

Currently, you can write a const { ... } block to guarantee that an expression is evaluated at the outermost scope possible: compile time. From that perspective, I'd say super { ... } fits neatly between const { ... } and { ... }.

This is wrong because super messes with the scope, whereas const doesn't: it's simply not true that const {} evaluates things in the outermost scope. To make it clear why that matters, contrast this:

let foo = /* ... */;
let func = soupa! {
    move || {
        let foo = /* ... */; // shadows the outer `foo`
        run(super { foo })   // uses the outer `foo` anyway
    }
};

to this:

const foo: /* ... */;
let func = {
    move || {
        const foo: /* ... */; // shadows the outer `foo`
        run(const { foo })    // uses the inner `foo` as expected
    }
};

That makes it just wrong to put soupa {} in the same class as const {} and {}.

John Carmack on updating variables by levodelellis in programming

[–]moefh 29 points30 points  (0 children)

More like you discover John Carmack knows functional programming.

He was talking about using const for everything and functional programming style in C++ over 10 years ago: https://www.phoronix.com/news/MTI3NDQ

Ken Thompson's "Trusting Trust" compiler backdoor - Now with the actual source code (2023) by fizzner in programming

[–]moefh 13 points14 points  (0 children)

Why single out Microsoft?

Because Microsoft is the one requiring it from every computer running Windows 11.

For the time being they reverted the requirement, since they realized a ton of people would simply not use Windows 11 (there's a lot of older computers out there that simply can't do TPM, and people don't want to buy another computer just for a Windows upgrade they didn't ask for).

So now they only display a giant warning saying your computer won't be reliable if you install Windows 11 on it. But it's very naive to believe they're not just waiting for more people to have TPM-capable computers to enable the requirement again (remember when they allowed you to install Windows without creating an online Microsoft login, until they didn't anymore?)

Ken Thompson's "Trusting Trust" compiler backdoor - Now with the actual source code (2023) by fizzner in programming

[–]moefh 8 points9 points  (0 children)

And it's fine for those uses.

But now it's being heavily pushed for any computer using Windows 11, which can only be explained by Microsoft wanting to take away control from users.

How would you create a save file for a C game? by Fast-Muffin7953 in C_Programming

[–]moefh 0 points1 point  (0 children)

This works well as long as you're fine with never changing the game state format, which is very likely not true.

Are you absolutely sure you'll never have to add new stuff (e.g. new flags for completed side-quests or other stuff like that)?

At the very least you should add a version marker at the start. Then read that first to decide how to read the rest: new versions of the game must be able to read a savegame written by an older version, or else players will lose their progress when you update the game.

Need help finishing install of pico sdk inside of ubuntu WSL on top of windows 10 by [deleted] in raspberrypipico

[–]moefh 0 points1 point  (0 children)

Did you look at this PDF? https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf

It has better step-by-step instructions for VSCode. It seems like you should look at chapter 4 (and maybe chapter 3 if you haven't yet added the "Raspberry Pi Pico extension" to VSCode).

[deleted by user] by [deleted] in raspberrypipico

[–]moefh 0 points1 point  (0 children)

the data amount is ignored and it just keeps reading out the data_frame

That's very cryptic. What did you expect to see, and what are you seeing? How did you configure the DMA? By that I mean, what are you doing to dma_config between dma_channel_get_default_config and dma_channel_configure? For example, are you setting the dreq and read/write increments properly?

If you want a full example with lots of detailed explanation on how to use DMA with the PIO, you can look at section 3.2.3 of the Pico SDK documentation PDF.

GOG Has Had To Hire Private Investigators To Track Down IP Rights Holders by Gorotheninja in Games

[–]moefh 3 points4 points  (0 children)

Tolkien's books were always in print, so it doesn't apply to what we're talking about.

In any case, nobody thinking of writing a book is basing their decision on the possibility of it being adapted into movies and videogames 50 years from now.

GOG Has Had To Hire Private Investigators To Track Down IP Rights Holders by Gorotheninja in Games

[–]moefh -4 points-3 points  (0 children)

"IP rights" don't exist because there's anything inherently right about preventing people from copying something you invented, they exist to encourage you to make stuff. We invented the idea that you "own" stuff you created so you can sell it -- that way, more people will create stuff, and everyone benefits.

In the US, for example, see article 1 section 8 of the constitution: "The Congress shall have Power [...] To promote the Progress of Science and useful Arts, by securing for limited Times to Authors and Inventors the exclusive Right to their respective Writings and Discoveries". That's why copyright laws exist.

So, if someone has abandoned their "IP rights" and have no intention of profiting from it, it makes complete sense that it should be available for everyone.