What are the downsides to defining a C macro that works like the Python "with" statement?
Question: After playing around a bit with C preprocessors, I thought of a way to have
something similar to a Pythonian with control structure, defined like this:

    
    
    #define with(var) for(int i##__LINE__=0;i##__LINE__<1;)for(var;i##__LINE__<1;++i##__LINE__)
    

Sample usage:

    
    
    #include <cstdio>
    #include "FileClass.hpp"
    #include "with.hpp"
    
    int main(){
        with(FileClass file("test.txt")){
            printf("%s\n",file.readlines().c_str());}
        return 0;}
    

The idea is that a doubly-nested for loop has an outer obfuscated iteration
variable which is incremented once in the inner loop to break it. This causes
the following code to be executed once with var in its scope.

Are there any downsides to this? If I obfuscate the iteration variable enough,
there would be almost no chance of having a name clash, it uses only standard
preprocessor features in a way that doesn't seem to have any possibility of
backfiring, and it's very easy to understand.

It almost seems too good to be true - is there any reason this isn't used
everywhere?


Answer: > is there any reason this isn't used everywhere?

Yes, C++ is not Python, and if I understood your code correctly, this does
exactly the same:

    
    
    {
      FileClass file("test.txt");
      printf("%s\n", file.readlines().c_str());
    }
    

So, what are the downsides? Unnatural syntax, usage of the preprocessor for
code obfuscation, achieving the same thing as above with much more boilerplate
code, and unidiomatic use of C++. Enough?

C++ has the _very_ important concept of _value types_ and scope-based
deterministic destruction of stack variables. This leads to _very_ important
idioms like SBRM (scope-bound resource management, also called RAII).

