Quantcast
Viewing all articles
Browse latest Browse all 42

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. Similarly, argc % 2 is weird, why would you check for an even amount of arguments? Check for an exact amount of arguments, no more, no less.

  • Similarly, you should be able to keep all error handling out of the loops and just do it once. Keep it simple.

  • I'd expect the various valid trigraph sequences to be stored in some manner of table, rather than a big switch. For example, you could sacrifice 128 bytes data for a fast lookup table based on 7 bit ASCII:

    const char trigraph [128] = {  ['#'] = '=',  ['['] = '(',  ...};char in  = ... // input from filechar out = trigraph[in];if(out != 0) // was it a candidate for trigraph replacement?{    // printf("??%c", out); etc

Viewing all articles
Browse latest Browse all 42

Trending Articles