Блог пользователя ivplay

Автор ivplay, 10 лет назад, По-английски

It happened to me many times that I submitted my solution without commenting out freopen and got compilation error! How virtual judges determines that I am using freopen/fopen? Interesting part is, I use - #define filein(x) freopen(x,"r",stdin) - #define fileout(x) freopen(x,"w",stdout)

it compiles when I do not call them. but it gets compilation error when I use filein("input.txt"); My question is, is it should be compilation error even though I use it! How they detect it!

  • Проголосовать: нравится
  • -8
  • Проголосовать: не нравится

»
10 лет назад, # |
Rev. 2   Проголосовать: нравится +7 Проголосовать: не нравится

You forgot the quotes

»
10 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

The compilation error should be a Sandbox (I guess), it disallow most dangerous operations like handling files and network.

The other part, when you write macros like: "#define filein(x) freopen(x,"r",stdin)"

Macros are handled by the preprocessor, in your example, each time "filein(x)" appears in the source is replaced to "freopen(x,"r",stdin)", obviously changing the variables, the output generated by the preprocessor is passed to the compiler, by that, if you declare the macro but is not used in your code, doesn't show you compilation error.