Quantcast
Channel: User Lundin - Code Review Stack Exchange
Browsing latest articles
Browse All 37 View Live
↧

Comment by Lundin on State-machine class based upon arduino toolchain

@bask185 I interact with hundreds of people on the SE network each week. I have no idea who you are and have no "past" with you. And regardless, stubbornly refusing to adopt what's widely considered...

View Article


Comment by Lundin on A beginner's implementation of tic-tac-toe

@chux-ReinstateMonica C17 6.11.6 "The use of function declarators with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature."

View Article

Comment by Lundin on A beginner's implementation of tic-tac-toe

@chux-ReinstateMonica It's somewhat common coding style to use capital letters for constants, not just for macros.

View Article

Comment by Lundin on Entropy of String in C

Maybe a hash table would be useful?

View Article

Comment by Lundin on Concept of implementing "generic" types in C using macros

@JohnKimble There's both better type safety and less layers in-between this way. Though if you wish to implement some C++ vector-like container, there's probably no sensible way to avoid dynamic memory...

View Article


Comment by Lundin on touch command in C

The most correct fix is rather to input sanitize argv. Can be as easy as a memchr search for \0. Then you need not concern yourself with potential overflows later on.

View Article

Comment by Lundin on Portable noreturn in C/C++ between compilers

"this is intended to be portable all C and C++ standards" I don't think that's possible since the feature wasn't present back in the days. Well-written, modern code uses stdnoreturn.h and does not rely...

View Article

Comment by Lundin on Standard C overflow-safe arithmetic functions

Never use mysterious crap types over standardized integer types. Every single #define in this code needs to go.

View Article


Comment by Lundin on Standard C overflow-safe arithmetic functions

Good review, I strongly agree with everything said.

View Article


Comment by Lundin on Function to skip characters

Many aren't aware of the standard strcspn function. It returns the length of a string until the point where one out of several characters has been found. size_t i = strcspn(str, " \t\r\n"); /* whatever...

View Article

Comment by Lundin on C string parser criticism

@user1593842 Because you say so or because of actual arguments?

View Article

Answer by Lundin for Trigraph translator

There is absolutely no reason why WRITE_BUFFER should be a macro and not a function.Don't do exotic stuff like --argc; ++argv;. C programmers expect argument 0 to be the name of the executable....

View Article

Answer by Lundin for Double-ended queue for Embedded Systems with different...

Couple of bugs:queue.c doesn't #include <string.h>.Casting the pointer parameters passed to memset and memcpy isn't necessary, but can hide bugs.Your macros do non-standard pointer arithmetic on...

View Article


Answer by Lundin for Simple state machine

Implementing state machines with a table with function pointers is very common. The table should however be read-only and preferably stored in flash. This does however seem to be some PC-like ARM with...

View Article

Answer by Lundin for Statically allocated memory pool in C for embedded systems

Design:Consider making an API that enforces the caller to allocate aligned chunks. This will make the code much more robust on 32 bit systems. You can still let them state the desired size in bytes,...

View Article


Answer by Lundin for Generic Vector implemented in C language

Design:Overall, function naming and const correctness etc looks good. The header is nicely formatted and easy to read. Most function names are self-explanatory, though I wouldn't use start and...

View Article

Answer by Lundin for Calculate the free electron concentration and drift...

In addition to the other reviews, some misc comments:The switch RUN_REAL_PROGRAM is weird, doesn't seem like something that should be part of the final program - remove it.In general, avoid...

View Article


Answer by Lundin for case-insensitive `strncmp()` for ASCII chars only (not...

Overall, checking byte by byte is fast on 8/16 bit CPUs since they typically don't care about alignment, but slow on 32 bit or larger CPUs. So the byte by byte loop is fine if low-end MCUs are the...

View Article

Answer by Lundin for Simple Tetris game

Always write source code and comments in English (I'm not a native English speaker either). You will sooner or later need to share code with other people around the world, like you just did here and...

View Article

Answer by Lundin for Remove all comments from a C program

First a classic bug: char cur_char; ... (cur_char = getchar()) != EOF. The variable must be int not char or you can't compare it with EOF. Yeah it's really stupid that getchar gets an int, not a char,...

View Article

Answer by Lundin for c - memcopy for embedded system

Unfortunately, this function is quite naively written to the point where you would be much better off with a plain byte-by-byte loop:for(size_t i=0; i<size; i++){ src[i] = dst[i];}Benchmark and...

View Article


Answer by Lundin for Embedded IoT: local data storage (Second Update)

Overall the code is well-written and easy to read. I found no major things to remark on, just details:cvaluetypes is only used by the .c file and should be declared static, to achieve private...

View Article


Answer by Lundin for Multi-threaded application performance in C

First of all, get rid of your secret macro language so that other programmers who don't know your what your secret names mean can read the code. This means replace the mysterious, unreadable...

View Article

Answer by Lundin for C function that emulates string concatenation operator...

The main issue with this is that variadic functions have non-existent type safety. It is better to avoid them - it's one of those old things in C that's simply broken.I would suggest to instead write a...

View Article

Answer by Lundin for Implementation of the trigonometric functions for real...

One remark is that you should get rid of all the needless branching and code repetition. It's bad for performance and code maintenance both.Given an angle you should be able to:Take it's absolute...

View Article


Answer by Lundin for Fixed memory manager in C

You can't really implement a memory manager system like this in standard C. It would have to rely on standard extensions and specific compiler options. The main reason for this is "the strict aliasing...

View Article

Answer by Lundin for Unsigned 32-bit integer to binary string function

As already said in other reviews, you should switch to caller allocation. And there's no initialize the string at all, just overwrite all of it.As for the algorithm itself, or in general, go with...

View Article

Answer by Lundin for tokenize char array with PolarSSL library

I don't know how this lib works but in general terms, replacing the switch with a look-up table should help with readability/maintenance and performance both. Since there's just 15 items, we don't need...

View Article

Answer by Lundin for Ring buffer for Arduino

Review addressing the embedded system aspects, assuming the target is Arduino/AVR 328P:Implementing destructors for a class to be used in a bare metal embedded system is very fishy. If you find...

View Article



Answer by Lundin for Software ECC embedded with a parallel NAND Flash interface

From what I remember ST Cortex M4 has some "wannabe cache"-like feature, "ART accelerator", something like that. This is supposedly mainly there to reduce wait states. But if it works like normal...

View Article

Answer by Lundin for Circle & Sphere Calculator

It's bad practice to use non-standard functions needlessly. Instead of calling non-standard _stricmp all over the place, you can just iterate over the input string once and call tolower on every...

View Article

Answer by Lundin for My first C program: quadratic formula calculator code

Overall clear and readable. Some remarks:atoi is one of those standard library functions that should never be used. It is 100% equivalent to strtol family of functions, except that the latter have...

View Article

Answer by Lundin for UPDATED: str_join() function, not present in standard C...

After some long discussion in comments regarding changing the whole concept... here are the main problems:Variadic functions are slow, very type-unsafe and should be avoided in general.Caller...

View Article


Answer by Lundin for substr() function, not present in standard C library

Error checks like if ((!str) || (!*str)) and if ((start_index < 0) || (end_index < 0) || (end_index < start_index)) etc don't belong inside a library function. It's the caller's responsibility...

View Article

Answer by Lundin for Text-based Tic-Tac-Toe in C

The overall pattern here is that you write code in needlessly complex ways. Good C programming practice is to write code as simple as possible, obeying the KISS principle.Using octal notation with no...

View Article

Answer by Lundin for K&R Exercise 3-3: Expand Shorthand Notations (e.g. a-d...

I strongly recommend to avoid K&R since it teaches bad style and is very much outdated. This review will focus on general C programming rather than commenting on your specific algorithm.Invalid...

View Article


Answer by Lundin for "Smart" (ish) pointer in C

It isn't possible to implement smart pointers sensibly in C because it lacks "RAII". It would be possible to implement a garbage collector by multi-threading, but one of the benefits of using C in the...

View Article

Browsing latest articles
Browse All 37 View Live




<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>