Reputation
4,422
Top tag
Next privilege 5,000 Rep.
Approve tag wiki edits
Badges
8 18
Newest
 Good Answer
Impact
~428k people reached

  • 0 posts edited
  • 0 helpful flags
  • 188 votes cast
Oct
2
comment Should I stop using the term C/C++?
@cmaster: For situations where the thing being assigned is a simple variable, using that as the sizeof argument is fine, but if it's being assigned to myArray[i*16+j], foo->data, etc. duplicating the target lvalue can be irksome. Further, the fact that C has two good ways of writing malloc() which are pretty well equivalent and C++ only likes one of them doesn't violate Stroustrup's claim nearly as strongly as does the C++ inability (so far as I can tell) to declare enums that support the standard pre-defined arithmetic operators.
Oct
2
revised Should I stop using the term C/C++?
Fixed "95" to "98".
Oct
2
comment Are there real world examples demonstrating reasonable performance improvement by using move semantics?
There are a number of places where code which knows that it holds the only pointer to an object can benefit from such knowledge. If code exposes an independent copy of a pointer, it may be difficult for it to discover when all independent copies have ceased to exist. On the other hand, it's often much easier, but almost as useful, for code to know that no independent copies of the pointer have ever existed. Move semantics increase the number of cases where code which will often hold the only reference to an object will be able to know that and exploit it.
Oct
2
comment Should I stop using the term C/C++?
...there are many cases where it makes sense for well-written C code to perform arithmetic on "enum" types [e.g. one might have many cases in a switch statement increment the state variable] but I don't know any way to declare a variable in C++ such that a debugger will regard it as an enumerated type and show its value symbolically, but it can be operated on without typecasts as though it were an integer type.
Oct
2
comment Should I stop using the term C/C++?
@cmaster: I think Stroustrup's claim was made before C99 added VLAs, and I favor someVar = (someType*)malloc(sizeof (someType)); since (1) the typecast will not prevent any decent compiler from squawking if no prototype for "malloc" is in scope, and (2) if someVar is a pointer to the wrong type, the above code will squawk. Without the typecast, it would compile but likely fail if the types are different sizes; further, even if the types are the same size now, changing the size of either type would make the code break. On the other hand...
Oct
2
comment Should I stop using the term C/C++?
...compile-time constants, port is constant but state isn't, or where neither port nor state are constants. Is there any way to accomplish that cleanly using templates or some other standard C++ mechanism, or is it only possible on compilers with gcc extensions?
Oct
2
comment Should I stop using the term C/C++?
@5gon12eder: I've never tried to link C++ code into a C project. Is it really as simple as having everything either be static/inline or extern "C" or are there other complications as well (e.g. static-object initialization, etc.)? Is there any way in C++ to make it so that foo(1234) will invoke a foo_const(1234) macro while foo(x) [where x is not a constant] will invoke a foo_var(x) function? There are many situations in embedded code where it may make sense for a "function" like SET_PORT(port, state) to have three-forms based upon whether port and state are both...
Oct
2
comment Should I stop using the term C/C++?
@BenVoigt: Mea culpa. I should have looked it up. The C++ version before C99. When C89 came out, it tried to make C more like C++, but C99 added a fair number of features which C++ was definitely not interested in (e.g. variable-length arrays). I don't program much in C++, but I think a few more C++ features would help C more than the divergent features have helped it.
Oct
1
answered Should I stop using the term C/C++?
Sep
28
answered Why is .NET VM based?
Sep
25
comment Why are the sizes of programs so large?
A related factor is that in systems which use static linking, a linker may only need to pull in code which is actually used [some linkers would always pull in everything, but better ones tried to be selective]. When using dynamic linking, especially if modules can be shared, even if the first code that installs a module only needs one function from it, there's no way of knowing what functions may be needed by other code that wants to share the module.
Sep
24
comment Why is (position < size) such a prevalent pattern in conditionals?
@ViliamBúr: I like your suggestion, but think if (newSize > array.length) array.expandSomehow(); even though there the purpose would be to adjust the array size. I think that form is probably used because newSize is apt to be the more recently-computed value.
Sep
22
comment Debug function input vs expecting code users to read the documentation - How far do I go?
Consider a function which is supposed to report whether a point is within a rectangle defined by the x and y coordinates of its upper-left corner along with its width and height. If rectangles with an X of 1 and a Width of 2147483646 are valid, and likewise rectangles with an X of 2147483646 and a Width of 1, what sort of validation should such a function be expected to perform to ensure that it does not flow an overflow exception?
Sep
22
comment Debug function input vs expecting code users to read the documentation - How far do I go?
What about situations where input upon which certain computations can be performed without overflow is valid, and input upon which those computations would overflow is invalid? In many cases, the amount of human and CPU work to determine whether a given input would cause some computations to overflow may exceed the amount of work (both kinds) needed for the non-overflow case.
Sep
21
comment Why is String immutable in Java?
@JoachimSauer: How was having an immutable string type "radical"? They were pretty commonplace in late-1970s BASIC interpreters.
Sep
21
comment Why do build tools use a scripting language different than underlying programming language?
@AndresF.: Things like make files require a mixture of approaches. The desired output state is specified declaratively, but the actions necessary to achieve that state are specified imperatively.
Sep
14
comment Why would programmers ignore ISO standards?
...the contents to be overprinted) having a combined character would have made it easier to send other control code (like BEL) after a CR-LF code without impeding transmission speed, and would also have also improved transmission speed in the event that a file was being received to tape for use on a system which could add the necessary delays when reading the tape.
Sep
14
comment Why would programmers ignore ISO standards?
@JensG: If I were around when ASCII was invented, I would have specified that a teletype should home the cursor on receipt of character 000000x1, and advanced the paper on receipt of character 0000001x. Character code 00000011 would satisfy both properties, though the character following a "home-cursor" character would be required to be a non-printing character in any event, Both CR and LF are useful in isolation, and while there wasn't initially much disadvantage to requiring two characters be sent (overprinting a line would require sending a CR followed by a null, followed by...
Sep
14
comment Why does ISO 8859-1 contain letter-free diacritics?
@Heinzi: Also, while it's been ages since I've used one, some early CRT terminals used storage tubes which weren't scanned continuously but instead had a regeneration grid which would cause any information drawn to them to remain visible for many minutes (there was a touchy adjustment which, if set too low, would cause the screen to fade more quickly, and if set too high would cause the whole screen to start glowing). There wasn't any way to partially-erase the screen--the only operation was to erase everything (which would make the screen flash brightly).
Sep
14
comment Why does ISO 8859-1 contain letter-free diacritics?
@Heinzi: I've worked with an ASR-33 terminal where a backspace followed by another character would cause both to be printed on top of each other. What was interesting is that if one was punching a tape and made a mistake, the way to correct it was to hit the "back up" button on the punch and then push the "rub out" button. The "rub-out" key generates all-bits-one (DEL) which is ignored just like all-bits-zero (NUL). The purpose of the "delete" character code wasn't actually to make the recipient delete anything, but rather to be a code which, if overpunched on anything, would obliterate it.