Nested preprocessors bug? #1867
-
It seems this piece of code is invalid in C# (which should not be!)
The compiler generates
note that error is generated for
I need this behaviour in my application as I generate cs# files that are valid in both c++ and c# |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I think this behaves according to the specification (emphasis mine):
Since Since I don't think being able to write source that is valid for both C++ and C# is a goal of C#, you would probably need to find a different reason to change this. Can't you use different syntax to achieve the same effect, like |
Beta Was this translation helpful? Give feedback.
-
Times like this it would be nice to have some sort of #IfThisCompilesThenGreatButOtherwiseJustIgnoreIt, but I can't imagine a proposal like that getting much traction. |
Beta Was this translation helpful? Give feedback.
-
Did you consider generating C++/cli instead of C#? |
Beta Was this translation helpful? Give feedback.
I think this behaves according to the specification (emphasis mine):
Since
#define SOMETHING 1
is not a lexically correct pre-processing directive in C#, the code is correctly reported as invalid C# by the compiler.Since I don't think being able to write source that is valid for both C++ and C# is a goal of C#, you would probably need to f…