2

Recently faced with an interesting interpretation of the EOF character console windows. On some machines running windows 7 code putchar (255) && putchar (-1) is displayed as a space character, and some as 'a' character. The second confuses me. Tell me please, why is this happening?

haccks
  • 104,019
  • 25
  • 176
  • 264
iGriffer
  • 250
  • 4
  • 16

2 Answers2

2

The actual value of EOF is system-dependent (but is commonly -1, such as in glibc) and is unequal to any valid character code.

Sadique
  • 22,572
  • 7
  • 65
  • 91
  • I know about system-dependending EOF value, but whether to displaying of -1 code depend from compiler or console settings in windows? – iGriffer Oct 05 '13 at 08:37
  • 1
    The value of `EOF` is equal to any Character code. So the result can be anything in the world. So loosely speaking - yes, it may have happened due to the way your compiler has been implemented. – Sadique Oct 05 '13 at 08:42
2

EOF is not a character, it's more like a signal (not the Unix signal) indicating End-of-File. Is value is implementation dependent, but guaranteed to be unequal to any valid character, usually -1.

When you use putchar(EOF), or putchar(-1), it's converted to unsigned char, 255. But the ASCII value 255 isn't a printable character, the result varies in different machines.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294