Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C include paths: Safe to use hyphen & underscore?

I realise that this may be operating-system specific, but I am trying to write cross-platform GCC code. So would like to know if it really is best to avoid these, or if am forced to choose, which would be the safer bet.

like image 806
Engineer Avatar asked Apr 22 '26 11:04

Engineer


1 Answers

The syntax of header names is (C11, 6.4.7 par. 1):

header-name:
       < h-char-sequence >
       " q-char-sequence "
h-char-sequence:
       h-char
       h-char-sequence h-char
h-char:
          any member of the source character set except
                       the new-line character and >
q-char-sequence:
       q-char
       q-char-sequence q-char
q-char:
          any member of the source character set except
                       the new-line character and "

Both - and _ are part of the basic source character set (5.2.1 par. 3). But the standard leaves much stuff related to #include implementation-defined.

In practice I don't see any problems in using them. I'm not aware of a file system that disallows or assigns a special meaning to them. This Wikipedia article doesn't list one either.

like image 198
cremno Avatar answered Apr 25 '26 05:04

cremno