Is this code behavior defined?

I believe it’s unspecified whether 0 or 1 is stored in m[0], but it’s not undefined behavior. The LHS and the RHS can occur in either order, but they’re both function calls, so they both have a sequence point at the start and end. There’s no danger of the two of them, collectively, accessing the … Read more

Why does it make a difference if left and right shift are used together in one expression or not?

This little test is actually more subtle than it looks as the behavior is implementation defined: unsigned char x = 255; no ambiguity here, x is an unsigned char with value 255, type unsigned char is guaranteed to have enough range to store 255. printf(“%x\n”, x); This produces ff on standard output but it would … Read more

What does the period ‘.’ operator do in powershell?

The “.” dot sourcing operator will send AND receive variables from other scripts you have called. The “&” call operator will ONLY send variables. For instance, considering the following: Script 1 (call-operator.ps1): clear $funny = “laughing” $scriptpath = split-path -parent $MyInvocation.MyCommand.Definition $filename = “laughing.ps1” “Example 1:” # Call another script. Variables are passed only forward. … Read more

Why would someone use the

This allows you to do something like this: var myEnumValue = MyEnum.open | MyEnum.close; without needing to count bit values of multiples of 2. (like this): public enum MyEnum { open = 1, close = 2, Maybe = 4, …….. }

x > -1 vs x >= 0, is there a performance difference

It is very much dependent on the underlying architecture, but any difference will be minuscule. If anything, I’d expect (x >= 0) to be slightly faster, as comparison with 0 comes for free on some instruction sets (such as ARM). Of course, any sensible compiler will choose the best implementation regardless of which variant is … Read more

ruby: what does the asterisk in “p *1..10” mean

It’s the splat operator. You’ll often see it used to split an array into parameters to a function. def my_function(param1, param2, param3) param1 + param2 + param3 end my_values = [2, 3, 5] my_function(*my_values) # returns 10 More commonly it is used to accept an arbitrary number of arguments def my_other_function(to_add, *other_args) other_args.map { |arg| … Read more