Dtynin
Dtynin
Compile-Time Check for Node Limit in Custom Communication Function for PIC16F84A
Hey everyone, I’m working in Microchip Studio to create a custom communication function for a few PIC16F84A microcontrollers. I know there are built-in options like SPI, but I’m going the DIY route to learn more about the nitty-gritty of how this all works. Here’s what I’ve come up with so far:
void sendMessage(uint8_t node, uint8_t data);
void sendMessage(uint8_t node, uint8_t data);
Now, my setup only supports up to 4 nodes, so I want to make sure the node parameter doesn’t go above 4. Right now, I just have a simple runtime check:
if (node > 4) { return; }
if (node > 4) { return; }
But I’m thinking it’d be better to enforce this at compile time instead of waiting for runtime. This could make the code safer, maybe even run a bit faster. I haven’t tried anything specific yet, but I’m curious if there are any cool tricks or language features I could use for this, like static assertions or compile-time constants. Anyone out there tried something similar or have any tips?
1 replies