Open nerdralph opened 4 years ago
Thanks for the suggestions. The descriptor name definition looks definitely better, but it does not compile in my environment (I copy / paste your code into usb_intr.h). Here is the error:
.../projects/include/usb_intr.h:186: syntax error: token -> '"' ; column 73
enums: I agree about type safety argument of enums. For PC based apps and embedded projects compiled by fully fledged C compilers - by all means. For MCU projects that may be compiled (and ported) on feature-trimmed C compilers I prefer using plain defines. But fair point.
I just made a fork and will update the descriptor definition and create a pull request.
As for enums, they've been part of the language since K&R. What C compiler doesn't support enums?
Nice work! Coincidentally, I have recently been working on a better way to represent string descriptors. The most important thing I was trying to avoid was manual size calculations. Here's how I'd change your code:
The reason for subtracting 1 from the string size is because the null termination is not needed.
I'd also recommend enums instead of defines for things like USB_DESC_STR, since they provide type safety. i.e.: