Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • 1
    This is a good answer, but I'd appreciate details on why choose undefined behavior rather than unspecified behavior (i.e. the result will have some value, but no velociraptors are involved) . Commented Mar 19, 2015 at 8:43
  • @sbabbi: Making it undefined behavior means that a compiler can optimize int shift(int v, int n) { if (n >= 32) v=0; return v<<n;} by eliminating the first if(n>=32) v=0;, regardless of what the processor will do with the request, since if n is 32 or larger the C standard says the compiler can do whatever it wants. Commented Apr 17, 2015 at 23:45