Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1059691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:12:46+00:00 2026-05-16T18:12:46+00:00

I noticed that the C# compiler generates a ret instruction at the end of

  • 0

I noticed that the C# compiler generates a ret instruction at the end of void methods:

.method private hidebysig static void Main(string[] args) cil managed
{
    // method body
    L_0030: ret 
} 

I’ve written a compiler for .NET and it works regardless if I emit a ret statement or not (I’ve checked the generated IL and it’s indeed not in there).

I just wonder: Is ret on methods returning void required for anything? It doesn’t seem to do anything with the stack, so I believe it’s completely unnecessary for void methods, but I’d like to hear from someone who knows a bit more about the CLR?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:12:46+00:00Added an answer on May 16, 2026 at 6:12 pm

    According to the C# Standard (ECMA-334), a method is defined as the following:

    A method is a member that implements a computation or action that can be performed by an object or class.
    Methods have a (possibly empty) list of formal parameters, a return value (unless the method’s return-type is
    void), and are either static or non-static.

    (ECMA-334; 8.7.3: Methods).

    Now, the CLI standard defines the following:

    Control is not permitted to simply “fall through” the end of a method. All paths shall terminate
    with one of these instructions: ret, throw, jmp, or (tail. followed by call, calli, or callvirt).

    (ECMA-335; 12.4, 6)

    This means, that in C#, a method returning void does not need a return statement. However, as the C# compiler compiles the C# code to IL Code, which requires a path termination at the end of a method, it emits a ret to end the method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed that MIDL.exe only generates header file ( _h.h) and GUID file (
I've noticed that the C# compiler doesn't infer second generic parameter. Example: C++ template
I've noticed that some static analyzers operate on source code, while others operate on
I've noticed that every running C program has a private mapping called [stack] that
Recently I've been working with MSTest, and I noticed that the testframework generates accessor
I noticed that Google maps is providing directions in my local language (hungarian) when
I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but
I noticed that my Designer.vb file of one of my forms has a lot
We noticed that lots of bugs in our software developed in C# (or Java)
i noticed that paypal displays a very different favicon, one that's not just a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.