38

I started studying old C code (Unix v6) and I'm wondering what is the purpose of a single # in the beginning of the .c file. For example from https://github.com/lsahn-gh/unix-v6/blob/master/sys%2Fken%2Falloc.c

#
/*
 */

#include "../param.h" #include "../systm.h" #include "../filsys.h" ...

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
g0mb4
  • 701

3 Answers3

65

From Stephen Kitt's answer on the Retrocomputing Stack Exchange:

Dennis M. Ritchie’s The Development of the C Language paper gives this context:

[...] The preprocessor was originally considered an optional adjunct to the language itself. Indeed, for some years, it was not even invoked unless the source program contained a special signal at its beginning.

[...] The “special signal at its beginning” is # as the very first character.

muru
  • 72,889
g0mb4
  • 701
13

It is a no-op. From one of the standards (the definition has not changed):

3.8.7 Null directive

Semantics

A preprocessing directive of the form

    #  new-line

has no effect.

As for the purpose, it's been asked before, check this for example. At the time it might have had something to do with readibility, since the line with # is visible only in the source, the preprocessor does not output anything at all. But that's just guessing, in practice it has been and still is a no-op.

3

That declares the line to be a preprocessor directive, not unique to just old C code.

https://stackoverflow.com/questions/66548702/what-do-you-call-in-c-and-c

https://en.wikipedia.org/wiki/C_preprocessor

https://cplusplus.com/doc/tutorial/preprocessor/

ron
  • 6,575