17

Today, I found this gem here in the codebase I've taken over:

#define BYTE unsigned char

FFS, use typedef, it's there for a reason. Solving the puzzle in the first comment.

Comments
  • 6
    As soon as you use the define way instead of typedef on pointer types, you will encounter interesting compiler messages once you declare several pointers at once and try to use them.
  • 0
    More copypasta from stack overflow i assume?
  • 3
    @arcsector Nah, that codebase is older than Stackoverflow so that the devs cannot have copy/pasted any bad answer from SO into their code.
  • 5
    I've always had the impression that #define is a bit of a poor solution in most cases. What's your opinion of when #define is used exactly correctly?
  • 1
    @AlgoRythm Whenever a purely textual replacement in awk/sed style is what you want. I use it mostly for expressions and conditional compiles.

    Function like macros work also, but they have the issue of side effects in the arguments, and having a static inline function (sometimes even in a header file) is often a better alternative.
  • 1
    @Fast-Nop I think I have used it for conditional compiles and a few constants
Add Comment