Reputation
4,057
Top tag
Next privilege 5,000 Rep.
Approve tag wiki edits
Badges
7 16
Newest
 Talkative
Impact
~299k people reached

  • 0 posts edited
  • 0 helpful flags
  • 173 votes cast
Aug
26
comment Is this XOR value swap algorithm still in use or useful
Registers aren't really so plentiful in many contexts. Even if a processor has an ample supply of registers, every register used in an ISR is a register which must be saved beforehand and restored afterward. If an ISR takes a twenty cycles, and is supposed to run every forty cycles, each extra cycle added to the ISR will degrade system performance be five percentage points.
Aug
26
comment Why do arrays in .Net have Length but other collection types have Count?
@combinatorics: I find it odd that StringBuilder includes a property setter for length, but not content; indeed, I don't know any way to set a string builder's concent except by clearing it and appending the content. I would think it would have been more natural for StringBuilder to have a read-only Length property but include Truncate, Pad, and PadOrTruncate, methods to set the length (with the methods other than Pad including a parameter for the padding character). I'd use Length because its purpose is to return the Length of the currently-encapsulated string.
Aug
22
awarded  Talkative
Aug
16
comment When did Undefined Behavior in C jump the causality barrier
...will always include code to prevent overflows in any cases where they don't want to launch nuclear missiles." Historically, given the specification "write a function which, given two arguments of type 'int', returns the product if it's representable as 'int', or else either terminates the program or returns an arbitrary number", int prod(int x, int y) {return x*y;} would have sufficed. Complying with "don't launch nukes" in strictly-compliant fashion, however, would require code that's harder to read and would almost certainly run much slower on many platforms.
Aug
16
comment When did Undefined Behavior in C jump the causality barrier
@rwong: As for the duplicate, the intention of my question was to ask when in human history the normative interpretation of Undefined Behavior with regard to e.g. overflow shifted from "If a platform's natural behavior would allow an application to satisfy its requirements without error checking, having the standard mandate any contrary behavior may increase the complexity of the source code, executable code, and compiler code necessary to have a program meet requirements, so the Standard should instead let the platform do what it does best" to "Compilers should assume that programmers...
Aug
16
comment When did Undefined Behavior in C jump the causality barrier
@rwong: I've read that appendix, but unfortunately it doesn't really make clear what can and cannot happen in various cases. For example, I don't think anything specifies whether int arr[256]; int16_t x; int16_t y=x & 255; arr[y]=123; would be required to set y to a value in the range 0..255 and thus ensure that arr[y] accessed a legitimate array element, or whether x & 255 would be a "fully" indeterminate value, such that the access of arr[y] would invoke critical UB.
Aug
14
comment When and why would we use immutable pointers?
@TruthOf42: Strings are used often enough that Java could have benefited from having a distinct variable type string which would behave like a primitive even if implementations would typically have a variable of type string encapsulate a reference to information stored elsewhere. As it is, reading the content from String requires double indirection; a string type could reduce that to single indirection by directly holding a char[] to which no reference exists outside of the string variable itself.
Aug
13
comment Why doesn't Java 8 include immutable collections?
@jhominal: IMHO, the proper pattern in many cases should be to have pairs of related mutable and immutable classes, analogous to String and StringBuilder. A BigIntAccumulator class could support a mutating Add method which was substantially faster than a non-mutating Plus method which had to construct a new instance. If the accumulator type allocated some extra storage for temporary calculations it could also support other mutating operations like MultiplyBy.
Aug
13
awarded  Good Answer
Aug
12
awarded  Nice Answer
Aug
12
answered Is there any practical way for a linked node structure to be immutable?
Aug
12
comment When did Undefined Behavior in C jump the causality barrier
...something other than their platforms' natural behavior, and would avoid in many cases avoid the need for programmers to use manual overflow handling at all. Major win. Unfortunately, compilers are going in the opposite direction. If a function's sole requirements are (1) compute x+y when representable as int (2) don't launch nuclear missiles when x+y is not representable as int, the amount of code (both source and, on some platforms, executable) required to meet requirement #2 may exceed that required for #1.
Aug
12
comment When did Undefined Behavior in C jump the causality barrier
...if run on a platform whose natural behavior would have met their requirements, might very well end up receiving useless compiler-generated overflow handling as well; as a consolation, though, it would remove the need for manual overflow handling in applications of the favored type which were run on the disfavored platform. A useful way to improve portability without such problems would have been to provide a means by which programmers could specify "I need overflows to be handled X way", which would only require compilers to include overflow handling when the program needed...
Aug
12
comment When did Undefined Behavior in C jump the causality barrier
If an application of the former type was run on an implementation which would hardware-trap integer overflows, the application could meet its requirements without any overflow-checking of its own. If an application of the latter type was run on an implementation where overflows would yield results that met requirements, it could likewise meet requirements without any overflow checking of its own. For the Standard to impose either form of overflow behavior would have meant that all applications of the other type would need manual overflow checking, and...
Aug
12
comment When did Undefined Behavior in C jump the causality barrier
@rwong: Exactly, and before 2009 that was the case. One benefit of leaving things undefined was that different applications have different requirements with regard to how they should handle invalid inputs, and different platforms' natural behaviors with invalid inputs will fit naturally with different application requirements. For some applications it is necessary that no seemingly-valid output will be produced unless an algorithm executes successfully (but may crash given invalid input); others must produce garbage output when given garbage input (but must not crash).
Aug
12
comment When did Undefined Behavior in C jump the causality barrier
...there are no downstream execution paths that don't invoke some form of Undefined Behavior. While the definition of "critical undefined behavior" given in (IIRC) Annex L is a bit vague, an implementation might reasonably implement static casting and virtual dispatch such that the indicated code would jump to an arbitrary address (it's critical UB). For it to always jump to Shape2D::Is­2D is actually better than the program deserves.
Aug
12
comment When did Undefined Behavior in C jump the causality barrier
@rwong: I don't see how that even violates the laws of time, much less causality. If illegitimate static casts terminated program execution (hardly an obscure execution model), and if the build model were such that no additional classes could be defined after linking, then no input to the program could cause shape->Is2D() to be invoked on an object that was not derived from Shape2D. There is a huge difference between optimizing out code which would only be relevant if a critical Undefined Behavior has already happened versus code which would only be relevant in cases where...
Aug
11
comment Why not just make non-parameterized queries return an error?
@CodesInChaos: True, and such a test might be accurate enough for this purpose, provided that anyone who had a reason for generating a string at runtime used a method which accepted a non-literal string rather than interning the runtime-generated string and using that (giving the non-literal-string method a different name would make it easy for code reviewers to inspect all uses of it).
Aug
11
answered Why not just make non-parameterized queries return an error?
Aug
10
comment Are data type declarators like “int” and “char” stored in RAM when a C program executes?
...being able to use a behavioral model where integer overflows yield partially-indeterminate values with loosely-defined semantics would be helpful in many others. Java requires that x<<y must yield x<<(y & 31). Hyper-modernists would like programmers who would write x<<y to instead write either x<<(y & 31), y > 31 ? 0 : x<<y, (y & 224) ? 0 : x<<(y & 31), or some other variation thereof, even if the programmer wouldn't care whether x<<32 yielded x or 0. I'd like to say x<<y can arbitrarily yield whichever of the indicated forms is fastest on the CPU being used.