Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] C++ preprocessor in .NET?

Started by Mithrandir Aug 4, 2006 at 12:43 PM 3 replies 2.1k views
Original Post
Mithrandir
Mithrandir
I'm working on a quick-and-dirty upgrade to an ancient tool, which, unfortunately relies on the C++ pre-processor. Basically, the tool takes a piece of code in a language that doesn't support macros, runs it through cl.exe like this: cl.exe /EP /u /nologo filename.ext > temp.out The /EP parameter disables everything except the pre-processor pass and temp.out holds an expanded version of the file, which the tool then goes on to process some more. I've got everything down good except the preprocessor functionality. I can't seem to find any C++ pre-processing libraries for C#. Ideally I'd like to avoid messing around with temporary files as much as possible, which is why I'd like to have an embedded (instead of shell-based) preprocessor in this tool. Does anyone know of any? I briefly considered looking into converting C++ preprocessors such as Boost.Wave into C#, but that is way too much effort for a simple tool, and we require this tool to be .NET.
This is my signature. There are many like it, but this one is mine. My signature is my best friend. It is my life. I must master it as I must master my life. My signature, without me, is useless. Without my signature, I am useless.
TheTroll
TheTroll
C# does not have a preprosser, that is why you don't see #defines and templates.

You could still run the file through a C++ pre-process step to get the output you want but that is kind of ugly.

theTroll
Mithrandir
Mithrandir
Right, I know that. The tool gives C++ macro functionality to any non-C++ language (an utterly stupid idea, I know, but I'm stuck with it) and the old version relies on the output of cl.exe to perform the preprocessing, which is extremely ugly and requires messing around with temporary files, which is a security risk and is going to be next-to-impossible eventually because the new policy around here aims to eventually disallow all disk access (don't ask me how we're supposed to get anything done...)
This is my signature. There are many like it, but this one is mine. My signature is my best friend. It is my life. I must master it as I must master my life. My signature, without me, is useless. Without my signature, I am useless.
bytecoder
bytecoder
Why don't you just use a pipe instead of redirecting it to a file?
snk_kid
snk_kid
Quote:
Original post by TheTroll
C# does not have a preprosser, that is why you don't see #defines and templates.


Actually it does but it's only subset of the C preprocessor, it's quite limited for acceptable reasons.

@Mithrandir: have you looked at nemerle before? it's quite similar to C# and has a real type-safe macro system.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.