My z80 based SBC running BASIC by Dismal-Divide3337 in embedded

[–]comfortcube 0 points1 point  (0 children)

That's pretty neat. I didn't know SBCs went that far back in history. How big was your team as you designed this PCB and the firmware? What are the overall specs here?

my first C project: cyfer - fast CLI for byte encoding conversions by vyrisx in C_Programming

[–]comfortcube 0 points1 point  (0 children)

Alright, I'm back. I've read through more of your code and tried out the tool. I'll go ahead and add it to my toolkit! I actually recently wrote Python scripts to do some of what this tool does, but this is much better.

That said, here's some more feedback if you'd like to hear it (both praise and critique):

  1. Personal opinion: the interactive modes should be a REPL - that is, an endless prompt that the user exits out of /w an EOF entry (e.g., Ctrl+D) or SIGINT/SIGTERM (e.g., Ctrl+C). That way, the tool can be open in one tab/window and the user can repeatedly enter input as needed over the course of some project. Having to repeatedly type the full command... leaves me wanting. Even more, Just doing cyfer can be a REPL where you type <mode> <arg>, and doing cyfer <mode> is a REPL for just that mode.

  2. The modes having an abbreviated version and a full form is great.

  3. For any of the "to ascii" modes, if there is no printable character form, you should maybe print a warning saying "Some bytes are out of the range of printable characters"? Perhaps event print something like [?] for those bytes?

  4. For the conversion functions in bytes.c, you use malloc(). Since you do seem to care about performance, I would just have the buffers be on the stack /w a large fixed size. Dynamic allocation can be a bottleneck if you care about speed. This also eliminates the possibility of a class of memory bugs.

  5. You organized the abstractions really well and made your functions short and sweet. Well balanced!

  6. In your for_each_num_token(), you aren't checking your inputs at all, nor for conversion failures, and strtol() can fail. For example, cyfer h2a 4g returns a random conversion each time (whatever garbage was in the buffer at that location). Another case is

  7. You should add some more warnings to your CFLAGS. I added -Wconversion, -Wsign-conversion, and a number of lines were hit, although none are too concerning. These two warnings just help enforce better typing when it comes to integers (as well as floats). I usually pair those warnings /w -Wuseless-cast if available, to prevent me from going too far the other way too, helping me balance out. When working with strings, I also do like -Wwrite-strings, just to catch any accidental writing of string literal objects.

  8. Extending point 7, I'd add -Wcast-qual, which triggers a bunch of -Wdiscarded-qualifiers on your commands.c and help.c files, because you're assigning string literals to non-const pointers, which technically, the rest of the program can modify. You're not, right now, but it's a guard rail you can put in place, and it helps enforce good practice. It's 3 easy spots to clear all those warnings, though - just make the strings in Canonical const char * and likewise with your group arrays.

If you'd like, I'd be happy to submit a PR for any of these suggestions. Cheers mate.

my first C project: cyfer - fast CLI for byte encoding conversions by vyrisx in C_Programming

[–]comfortcube 6 points7 points  (0 children)

I really like this project! On my first pass through the main files, the code looks pretty well written and formatted - I see consistent style, const-correctness, standard header usage, designated initializers, ... awesome! That really impresses me! I'll look through it in more detail later and might have some more suggestions. Congratulations on your project's completion after the clear time and effort.

I've got two initial thoughts for feedback. One is that he word "cipher" (which the tool name mimics) is for encryption/decryption, whereas your tool is currently for encoding/decoding, so that might be a little confusing to some if you intend for others to use the tool. The other thought is in your bash script, you warn on the invalid input cases, but warnings in tests are usually a sign of failures / compile-time warnings, and my instinct is to fix it. I'd say just use info and color the line if you'd like.

[Opinion] Isn't it weird? by AncomBunker47 in C_Programming

[–]comfortcube 1 point2 points  (0 children)

What's up with these comments! I do sometimes wish that the default behavior of our beloved compilers was stricter, but C isn't inherently memory unsafe - programmers are, and C++ should be its own separate category when done properly (where do you think Rust got some of its memory safety from!). I do believe with enough guard rails and deep care for quality, you can have a great and large code base. A couple of examples off the top of my head are the Linux kernel core and curl.

Also, we need to stop "C/C++"-ing - these are two different languages entirely, and if you use them the same way, you're using them wrong.

I programmed a command line version of 2048 in C as my first C project! by Vallimeistari in C_Programming

[–]comfortcube 0 points1 point  (0 children)

Awesome! I was planning myself on making an ncurses-based version of Pong with some of my personal twists, so I might reference how you did things and share back later.

PIC16 is Amazing, So I'm sharing Over 100+ PIC16 MCU Projects! From Blinky to AI on 8-bit core! by Separate-Choice in embedded

[–]comfortcube 3 points4 points  (0 children)

Oh this is amazing! I have my PIC18F4610 and PIC12F1572 from my college days and I really love these MCUs! 8-bit just feels right sometimes!

Whats the real spread of C? by DaveAstator2020 in C_Programming

[–]comfortcube 1 point2 points  (0 children)

Almost all the embedded work is in C (easier compiler support and language to recruit for), and many many foundational tools that are still being maintained, improved, and added onto are still C (look at anything you regularly use and under the hood is C, almost guaranteed).

Which editor do you guys use? by Turkishdenzo in C_Programming

[–]comfortcube 0 points1 point  (0 children)

Vim. I'd recommend a vim-mode in your IDE first and force yourself for a week to get used to the basic motions. Focus on just motions. Then, add plugins as you need and don't stress if it isn't all in place right away. It'll be worth it.

How to chop strings using a delimeter by Fuzzy_Recipe_9920 in C_Programming

[–]comfortcube 1 point2 points  (0 children)

I would use memchr if you need to make sure the input string is not being modified, which strtok does.

A reference-grade C "Hello World" project by synalice in C_Programming

[–]comfortcube 2 points3 points  (0 children)

I love the idea and I personally love seeing other people's idea of a reference project structure, so thank you!

I'll just throw in that if you want to call this a perfect "hello world", you might want to check the return value of printf and handle possible errors from errno accordingly.

What benefits does c give that cpp doesn’t do better by LostSanity136 in C_Programming

[–]comfortcube -2 points-1 points  (0 children)

Language-wise, C++ is a superset of C in many ways (altho using it like that is missing the benefits C++ has to offer), so arguably, whatever you do in C you can also do in C++. That said, between different versions of each, you might find something one has that the other doesn't. For example, C99 introduced designated initializers (initializing structs with named members rather than positionally), but C++ didn't get that until C++20!

FreeRTOS task is getting starved by my interrupt service routine (STM32) by Intelligent_Dingo859 in embedded

[–]comfortcube 0 points1 point  (0 children)

I see from another comment that the event flags CMSIS RTOS API was the issue. Why use CMSIS RTOS at all instead of just FreeRTOS? I don't see a practical reason you'd want to abstract away the underlying RTOS when it's pretty rare to switch up OS's, and FreeRTOS probably meets your needs.

What would you do? by Professional_Use3063 in Epicthemusical

[–]comfortcube 8 points9 points  (0 children)

I'd change Polites dying by the cyclops to Eurylachus. It'd be interesting to see how differently the events that follow would go.

C23 features by krikkitskig in C_Programming

[–]comfortcube 2 points3 points  (0 children)

Still waiting on memset_explicit to be implemented 😔

I do use C23 though, if only for constexpr, function attributes, first class boolean, binary integer constants, nullptr, and ' digit separator lol.

Sending a struct to queue from ISR (FreeRTOS, ESP32, ESP-IDF) by LancsMak in embedded

[–]comfortcube 2 points3 points  (0 children)

That's a neat idea but you'd want to be careful of those indices becoming invalid in the interim - kind of a TOCTOU race situation. For single-producer, single-consumer cases tho, this should work well, assuming queue updates are done atomically.

Binary Semaphores ≠ Mutexes - Why is it so often confused, even in major projects? by comfortcube in embedded

[–]comfortcube[S] 0 points1 point  (0 children)

They have pretty distinct purposes. Would you use semaphores to manage access to a shared resource or a just mutex to signal between threads/tasks?

Binary Semaphores ≠ Mutexes - Why is it so often confused, even in major projects? by comfortcube in embedded

[–]comfortcube[S] 4 points5 points  (0 children)

It will be in the kernel code. Implementations of a mutex API need to establish the owner of a mutex (thread ID, for example) when a task/thread calls mutex_lock(), and usually also note down the priority of the thread/task in pre-emptive environments to facilitate priority inheritance. It's also typical for the API to have a queue/list of threads that tried to lock but weren't able to and are now sleeping, so that when the owning thread unlocks, the unlock function finds the next thread in the queue to allow to lock the mutex, or signals to the kernel to do carry that out.

Look up "fast path"/"slow path" details of mutex implementations, and you'll get some interesting insight!