Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@electrineer Sorry, Arduino IDE has this by default and I'd installed it only to view this code so didn't bother customising anything.
-
I see what they are doing... I get it... but I don’t understand why, other than abstraction for readability... doesn’t affect performance at all due to it being pre processor... but if you were going to abstract it for readability i would think you’d make it more verbose
-
In this specific case: No idea.
Otherwise: Look at OpenSSL. Many of the backward compatible functionally is just implemented as a Macro over the newer functions. -
@irene because contrast hurts
I don't subscribe to the whole dark theme is l33t thing but a lot of people run devRant in dark mode and therefore my screenshot would hurt. -
LuxARTS16635yActually is not a very bad thing. Makes the code portable for various microcontrollers/boards/paltaforms.
For example, in Arduino you can turn on a pin with digitalWrite(n, 1) but if you are using lower level code you can do it with something like PORTN&=1<<n.
But if you are using other MCU, for example an STM32 with HAL library you would use HAL_GPIO_Write(PORTN, n, 1).
Makes sense to write a library where the header has the defines to the low level functions of the target MCU/board/plataform. -
@LuxARTS I don't mind that. I actually regularly transfer code from.Arduino to STM32 (I was actually doing just that here), I use #define and other abstractions all the time. What I do mind is function calls being hidden in things that look like values.
I mean, I would expect LCD_DC_0 to be some sort of value that I can throw into a function somewhere or do something else with. Instead it's actually a function call with side effects. If they'd instead abstracted it into a function-like thing, say, SET_LCD_DC_LOW(); now that makes sense.
Compare:
LCD_DC_0;
SET_LCD_DC_LOW();
The first one looks similar to this:
int x;
x; //means nothing
The second looks like a function call that does something, no confusion here. -
It’s not uncommon to find these exploring C code. It’s even better when something is defined and it looks like a built in 🤦🏻♂️
Why the actual fuck would you #define function calls into value-like things?!
Found when exploring the example code for some Chinese company's display module.
rant
#define sins