Backslashes in C includes…

Who’d have thought:

  1. that DOS backslashes in C include paths aren’t only ugly and a pain, but also not legal* C:

    If the characters ‚, \, „, //, or/* occur in the sequence between the < and > delimiters, the behavior is undefined. Similarly, if the characters ‚, \, //, or /* occur in the sequence between the “ delimiters, the behavior is undefined. A header name preprocessing token is recognized only within a #include preprocessing directive.

    (C99 6.4.7.3)

  2. … the C99 Standard is available for free online This links directly to the pdf containing the current standard, which lives here.
  3. It’s easy to fix:

    find . -name '*.[c|h]' -print0 | xargs -0 \
       ruby -i.bak -pe 'scan(/^\s*#include.*/){ gsub(/\\/, "/") }'
    
  4. * yeah, I know, it’s legal just undefined.
    ** this post inspired by this.

Comments are closed.