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. Other Discussions
  3. The Weird and The Wonderful
  4. Zero-choice alternative

Zero-choice alternative

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharp
24 Posts 14 Posters 1 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.
  • S supercat9

    If action is volatile, it would be possible for the second test to succeed even if the first fails. Indeed, if it's a memory-mapped mapped register, such behavior might even be expected.

    P Offline
    P Offline
    peterchen
    wrote on last edited by
    #21

    Reminds me of that little DOS / Win console classic to wait for a keystroke: if (!getch()) getch(); :cool: yes, this is the right way to do it

    Burning Chrome ^ | Linkify!| FoldWithUs! | sighist

    1 Reply Last reply
    0
    • B Bram Fokke

      Wouldn't float.IsNaN(x) be a more readable way to achieve that?

      M Offline
      M Offline
      Megidolaon
      wrote on last edited by
      #22

      Only decimal numbers have NaN as static class member (at least ni C#), natural numbers like int or short don't have it. Though if something is NaN, you would get an error the moment it's assigned to a natural number variable.

      1 Reply Last reply
      0
      • S supercat9

        If "foo" is volatile, the statement "if (foo == foo) bar();" must read the value of foo exactly twice and compare the two values read. If "foo" happens to be an address in normal RAM, the two reads would be most likely read the same data unless an interrupt or task switch happened to occur between them (not terribly likely). Not everything in a processor-based system is RAM, however. When a typical flash memory chip is performing a write cycle, consecutive read operations are guaranteed to return different data. If the generated code for the above 'if' statement didn't read 'foo' twice, the 'if' test would succeed even while the flash was still being written.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #23

        hey, if would b gr8 if u could explain wat u mean by variable being volatile

        Ravie Busie Coding is my birth-right and bugs are part of feature my code has!

        S 1 Reply Last reply
        0
        • L Lost User

          hey, if would b gr8 if u could explain wat u mean by variable being volatile

          Ravie Busie Coding is my birth-right and bugs are part of feature my code has!

          S Offline
          S Offline
          supercat9
          wrote on last edited by
          #24

          hey, if would b gr8 if u could explain wat u mean by variable being volatile This is not a place for programming questions, but in this context, a 'volatile' variable is one that is marked with the 'volatile' keyword. If a variable is declared volatile, expressions involving that variable may not be optimized. If 'foo' were not volatile, the code (assume foo, bar1, bar2, and bar3 are of type int):

          foo = bar1;
          bar2 = foo*25;
          bar3 = foo*25;
          foo = 8;

          could be safely replaced with:

          bar3 = bar2 = bar1 * 25;
          foo = 8;

          and indeed some compilers would make such a replacement. If 'foo' were volatile, however, all four of the original statements would have to be performed as-is, in sequence.

          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