Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Compiler question

Compiler question

Scheduled Pinned Locked Moved .NET (Core and Framework)
questiondebuggingannouncement
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Zorro_
    wrote on last edited by
    #1

    Hello, Today I've noticed something interesting to me and I'd like to understand. Let's say I have a function like this one:

    public enum SomeEnum
    {
    Value1 = 0,
    Value2 = 1
    }

    public void DoSomething(SomeEnum theEnum)
    {
    if(theEnum == SomeEnum.Value1)
    return;
    }

    When I build the project which is a ClassLibrary in Debug mode the compiler translates that to:

    public void DoSomething(SomeEnum theEnum)
    {
    if(theEnum == 0)
    {
    return;
    }
    }

    But when I build the same project in Release mode the result is:

    public void DoSomething(SomeEnum theEnum)
    {
    if(theEnum == null)
    {
    return;
    }
    }

    This seems to happen only when the Enum has two values. Anyone? Thanks.

    L T 2 Replies Last reply
    0
    • _ _Zorro_

      Hello, Today I've noticed something interesting to me and I'd like to understand. Let's say I have a function like this one:

      public enum SomeEnum
      {
      Value1 = 0,
      Value2 = 1
      }

      public void DoSomething(SomeEnum theEnum)
      {
      if(theEnum == SomeEnum.Value1)
      return;
      }

      When I build the project which is a ClassLibrary in Debug mode the compiler translates that to:

      public void DoSomething(SomeEnum theEnum)
      {
      if(theEnum == 0)
      {
      return;
      }
      }

      But when I build the same project in Release mode the result is:

      public void DoSomething(SomeEnum theEnum)
      {
      if(theEnum == null)
      {
      return;
      }
      }

      This seems to happen only when the Enum has two values. Anyone? Thanks.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      _Zorro_ wrote:

      the compiler translates that to...

      I doubt that very much. How do you make such observation? if reflector is involved (which version?), have a look at the IL code itself (not the decompiled "source" code), and show it here. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      _ 1 Reply Last reply
      0
      • _ _Zorro_

        Hello, Today I've noticed something interesting to me and I'd like to understand. Let's say I have a function like this one:

        public enum SomeEnum
        {
        Value1 = 0,
        Value2 = 1
        }

        public void DoSomething(SomeEnum theEnum)
        {
        if(theEnum == SomeEnum.Value1)
        return;
        }

        When I build the project which is a ClassLibrary in Debug mode the compiler translates that to:

        public void DoSomething(SomeEnum theEnum)
        {
        if(theEnum == 0)
        {
        return;
        }
        }

        But when I build the same project in Release mode the result is:

        public void DoSomething(SomeEnum theEnum)
        {
        if(theEnum == null)
        {
        return;
        }
        }

        This seems to happen only when the Enum has two values. Anyone? Thanks.

        T Offline
        T Offline
        T2102
        wrote on last edited by
        #3

        Also doubt that, especially since the optimizing compiler is likely to change the test to !theEnum instead of using the == operator.

        _ 1 Reply Last reply
        0
        • L Luc Pattyn

          _Zorro_ wrote:

          the compiler translates that to...

          I doubt that very much. How do you make such observation? if reflector is involved (which version?), have a look at the IL code itself (not the decompiled "source" code), and show it here. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

          _ Offline
          _ Offline
          _Zorro_
          wrote on last edited by
          #4

          Sorry for the delay, didn't checked my mail in a while :doh: Ok, I had to be drunk that day, even if i'm pretty sure of what I saw I am unable to reproduce that issue today... It's been an hour I'm trying with no success so I'll leave it there. I shouldn't have deleted my test project... :doh: Thank's to you both for your answers and happy new year!

          1 Reply Last reply
          0
          • T T2102

            Also doubt that, especially since the optimizing compiler is likely to change the test to !theEnum instead of using the == operator.

            _ Offline
            _ Offline
            _Zorro_
            wrote on last edited by
            #5

            My reply above, thanks!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups