ivplay's blog

By ivplay, 6 years ago, In English

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!

 
 
 
 
  • Vote: I like it
  • -8
  • Vote: I do not like it

»
6 years ago, # |
Rev. 2   Vote: I like it +7 Vote: I do not like it

You forgot the quotes

»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.