Home

Global flag for unsafe?

edited October 2019
Currently I need to write unsafe Main function code in just "C# Program" mode. Wondering is it possible to introduce a "global unsafe mode", so that I don't need to switch to "C# Program" to make the code working? (So I can delete ~3 lines of code and lots of tab :) )

unsafe void Main()
{
AVCodec* codec = avcodec_find_encoder_by_name("libx264");
AVCodecContext* c = CreateCodecContext(codec);
AVPacket* pkt = av_packet_alloc();
V(avcodec_open2(c, codec, null));

AVFrame* frame = av_frame_alloc();
frame->format = (int)c->pix_fmt;
frame->width = c->width;
frame->height = c->height;

V(av_frame_get_buffer(frame, 32));
using (FileStream file = File.Create(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @test.h264)))
{
WriteFrames(frame, c, pkt, file);
}
avcodec_free_context(&c);
av_frame_free(&frame);
av_packet_free(&pkt);
}
With "global unsafe mode ON", I can get rid of the Main function and the tabs.

AVCodec* codec = avcodec_find_encoder_by_name("libx264");
AVCodecContext* c = CreateCodecContext(codec);
AVPacket* pkt = av_packet_alloc();
V(avcodec_open2(c, codec, null));

AVFrame* frame = av_frame_alloc();
frame->format = (int)c->pix_fmt;
frame->width = c->width;
frame->height = c->height;

V(av_frame_get_buffer(frame, 32));
using (FileStream file = File.Create(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), @test.h264)))
{
WriteFrames(frame, c, pkt, file);
}
avcodec_free_context(&c);
av_frame_free(&frame);
av_packet_free(&pkt);

Comments

Sign In or Register to comment.