Possible to put compiler switches (e.g. /unsafe) in .cs file ? 
Author Message
 Possible to put compiler switches (e.g. /unsafe) in .cs file ?

Is it possible to put compiler switches inside a C#
source file (*.cs file)?

I don't mind if it is frowned upon like #pragma and
other platform/compiler dependent stuff.

I'm looking for something like this:

#pragma (compiler: "/unsafe")

Rant follows... (Please do not get distracted by the
following rant.  I'm only interested in getting
an answer to the problem above, not "answers" about
the content of the rant.)
=================================
I really hate having to recreate project settings
through the VC .NET GUI, or via editing the
.vcproj file or whatever.

I'm annoyed by the decision to make "/unsafe"
a compiler switch.  Lots of C# code will have
unsafe parts!  So why not have the compiler
figure out if your application has ANY unsafe
parts and compile accordingly!  It could be
a high-level warning, but at least ALLOW me to
use C# source code files to override policy
regarding stuff like this.  Many will choose the
GUI or hand-editing .vcproj for making
project changes, but I want the option of
overrides in source files, even if it's regarded
as an ugly hack!
=================================



Tue, 28 Jun 2005 19:43:12 GMT  
 Possible to put compiler switches (e.g. /unsafe) in .cs file ?
Yes

Just
Go project Property >> Configuration Property >> Debug >>Allow Unsafe Code
set to TRUE

Quote:
> Is it possible to put compiler switches inside a C#
> source file (*.cs file)?

> I don't mind if it is frowned upon like #pragma and
> other platform/compiler dependent stuff.

> I'm looking for something like this:

> #pragma (compiler: "/unsafe")

> Rant follows... (Please do not get distracted by the
> following rant.  I'm only interested in getting
> an answer to the problem above, not "answers" about
> the content of the rant.)
> =================================
> I really hate having to recreate project settings
> through the VC .NET GUI, or via editing the
> .vcproj file or whatever.

> I'm annoyed by the decision to make "/unsafe"
> a compiler switch.  Lots of C# code will have
> unsafe parts!  So why not have the compiler
> figure out if your application has ANY unsafe
> parts and compile accordingly!  It could be
> a high-level warning, but at least ALLOW me to
> use C# source code files to override policy
> regarding stuff like this.  Many will choose the
> GUI or hand-editing .vcproj for making
> project changes, but I want the option of
> overrides in source files, even if it's regarded
> as an ugly hack!
> =================================



Tue, 28 Jun 2005 20:09:48 GMT  
 Possible to put compiler switches (e.g. /unsafe) in .cs file ?


<SNIP>

Quote:
> Rant follows... (Please do not get distracted by the
> following rant.  I'm only interested in getting
> an answer to the problem above, not "answers" about
> the content of the rant.)
> =================================
> I really hate having to recreate project settings
> through the VC .NET GUI, or via editing the
> .vcproj file or whatever.

> I'm annoyed by the decision to make "/unsafe"
> a compiler switch.  Lots of C# code will have
> unsafe parts!  So why not have the compiler
> figure out if your application has ANY unsafe
> parts and compile accordingly!  It could be
> a high-level warning, but at least ALLOW me to
> use C# source code files to override policy
> regarding stuff like this.  Many will choose the
> GUI or hand-editing .vcproj for making
> project changes, but I want the option of
> overrides in source files, even if it's regarded
> as an ugly hack!
> =================================

It's not a hack, it's to discourage the use of
unsafe. Many C++ guys will come to C# and go "Oh boy,
I can just use pointers,{*filter*}this GC crap" and
that's wrong.

Most apps will _NOT_ have unsafe code. I'm glad
they add three levels of complication to discourage
it's use and I'm glad that I can set a policy on my
computer to prevent unsafe code.

-c



Wed, 29 Jun 2005 00:21:28 GMT  
 Possible to put compiler switches (e.g. /unsafe) in .cs file ?
To answer your real question: no, the C# compiler does not accept any
command-line arguments in source.  However, if you're using the command-line
compiler (instead of building from the IDE), you can put command-line
options in response files and pass those to the command-line compiler with a

There is a global response file called csc.rsp in the same directory as
csc.exe that the compiler always automatically reads options from (unless
you specify "/noconfig").  So if you're the type of guy like "anon" here who
has a set of default options that you have having to type over and over
again, just put then in the global response file and forget about them :)

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> Is it possible to put compiler switches inside a C#
> source file (*.cs file)?

> I don't mind if it is frowned upon like #pragma and
> other platform/compiler dependent stuff.

> I'm looking for something like this:

> #pragma (compiler: "/unsafe")

> Rant follows... (Please do not get distracted by the
> following rant.  I'm only interested in getting
> an answer to the problem above, not "answers" about
> the content of the rant.)
> =================================
> I really hate having to recreate project settings
> through the VC .NET GUI, or via editing the
> .vcproj file or whatever.

> I'm annoyed by the decision to make "/unsafe"
> a compiler switch.  Lots of C# code will have
> unsafe parts!  So why not have the compiler
> figure out if your application has ANY unsafe
> parts and compile accordingly!  It could be
> a high-level warning, but at least ALLOW me to
> use C# source code files to override policy
> regarding stuff like this.  Many will choose the
> GUI or hand-editing .vcproj for making
> project changes, but I want the option of
> overrides in source files, even if it's regarded
> as an ugly hack!
> =================================



Wed, 29 Jun 2005 05:58:27 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Newbie: separate big .cs file into small .cs files

2. Exception when starting program (program compiled with /unsafe - switch)

3. Switch to unsafe context

4. Saving C as a file to put through a compiler

5. Assembler possible in unsafe modified method? Is unsafe code optimized?

6. resx files needed for cs - files ??

7. CS files display in VS6 like CPP files ?

8. Compiler error CS 1595 - Help

9. Can I put a SWITCH in a *.H

10. Is it possible to put PictureBox on toolbar

11. putting end of file character in binary file (cutting the file short)

12. How is it possible to put an MDI child window in full screen

 

 
Powered by phpBB® Forum Software