Reputation
3,792
Top tag
Next privilege 5,000 Rep.
Approve tag wiki edits
Badges
6 14
Newest
 Yearling
Impact
~271k people reached

  • 0 posts edited
  • 0 helpful flags
  • 169 votes cast
2d
answered Why do we have to tell printf() the type of data in C?
2d
comment What would be the prototype of printf?
@dan04: Using __const and __restrict makes it possible to use the same header file in both C89 and C99 modes. A proper C89 compiler must work with correctly on a program that starts with #define restrict 12345 before its #include <stdio.h> but would not be required to work correctly if the program started with #define __restrict 12345.
2d
comment How does printf write to stdout?
I don't think vfprintf can work in terms of fputs, since printf("%c",0); is defined as causing a single 0 byte to be sent to standard output, and fputs is incapable of sending zero bytes. I would expect printf would use fwrite or an equivalent function; personally I wish there were a vprintf variant that were defined as accepting a void* and a pointer to a function that accepted a void*, a const char*, and number, and would returned int; such a variant could then be used to implement all the other standard forms of printf, and many additional forms besides.
2d
comment How much usage of “likely” and “unlikely” macros is too much?
@Peter: While it's too bad the syntax isn't nicer, notations as to what is likely or unlikely may provide useful information to humans who are reading code. For example, someone who saw if (likely(x==2 || x==3)) doOneThing(); else switch(x) { ... }, might judge that the programmer's use of an if for the values 2 and 3 was not merely a consequence of the programmer's not knowing that C can associate two case labels with a single handler.
2d
comment Undefined behaviours in C
Why did you strike out the whales and petunias? Given the code if (conditionThatWillNeverActuallyArise) DropWhalesAndPetunias(); someFunction(a,a++); a compiler could infer that because the program execution cannot possibly be defined if the above code is reached when conditionThatWillNeverActuallyArise is false, and might be defined if it's true (e.g. if DropWhalesAndPetunias calls exit), the call to DropWhalesAndPetunias() may as well be made unconditional.
2d
answered Giving variables default values vs. treating accessing an undefined variable as an error
2d
asked When did Undefined Behavior in C jump the causality barrier
Jul
27
comment Is it bad or good to wrap mutable objects in immutable containers?
An immutable container of mutable objects is immutable if no chain of events would cause a reference to those mutable objects to be exposed to code that would mutate them. If the code which creates the container has never exposed the mutable object to anything that might mutate it, and it knows that the container doesn't do so either, then the code which creates the container can know that it is immutable. The difficulty is that recipients of the container can't know what degree of care its creator took in guarding its contents, unless the container itself creates those contents.
Jul
27
comment Is it good practice to catch a checked exception and throw a RuntimeException?
It might be good to mention that this sort of issue can really wreak havoc in cases where a method runs a function which is supplied by its caller. The author of the method receiving the function will in many cases have no reason to know nor care what the caller is expecting it to do, nor what exceptions the caller might be expecting. If the code receiving the method isn't expecting it to throw a checked exception, the method being supplied may have to wrap any checked exceptions it would throw in unchecked exceptions that its supplier could then catch.
Jul
27
comment Why is object-level privacy difficult to use as a paradigm, and why is it desirable?
...any particular implementation needing to trust any other, provided that all implementations "trusted" an ArraySource<T> class. The list to be read would construct an ArraySource<T> which would receive (but never expose) its array internals; the destination would pass its backing store to that ArraySource<T> which would then perform a suitable bulk-copy operation (or sequence thereof). The ArraySource would need access to both IList<T>s' arrays, but neither IList<T> would ever be exposed to the other one's array.
Jul
27
comment Why is object-level privacy difficult to use as a paradigm, and why is it desirable?
@BillyONeal: Consider a type like List<T>, which has a private backing store of type T[]. If it's necessary to copy a range of items from one List<T> to another, the ability of one to access the T[] of the other allows such copies to be efficient, but does nothing to improve the efficiency of copying items from any other kind of IList<T> to a List<T> or vice versa. I would suggest that a better designed class could allow for efficient copying between any two implementations of IList<T> which store groups of consecutive data items consecutively in backing arrays, without...
Jul
27
comment Why is object-level privacy difficult to use as a paradigm, and why is it desirable?
...to have a class be substitutable for multiple other classes rather than actually inherit members from all of them, this approach would make it possible to have objects that behaved as though they inherited from multiple classes without requiring that they actually do so (a typical pattern would be for an object to inherit from one primary parent class, own a reference to an instance of each other supplemental parent class, and provide implementations of those latter classes' public members which chained to corresponding members of the owned instances.
Jul
27
comment Why is object-level privacy difficult to use as a paradigm, and why is it desirable?
@BillyONeal: If a language does not allow methods of a class Foo receiving a parameter of type Foo to use the private members of the object identified thereby, then the language can allow classes to be derived from Foo in two ways: (1) The derived class inherits all members of the base type; (2) The derived object does not inherit any members of the base type, and must implement all public members itself, but instances could then be passed to code expecting the base type. Since inheriting members from multiple base classes is problematic, and since it's generally more important...
Jul
26
answered Why would I care about the asymptotic growth of the lower bound of the worst case time/space?
Jul
26
comment When speaking, how can I say that the time complexity order of an algorithm is O(N log N)?
@Kevin: Logarithmic is four syllables, but "log-enn" is only two. Likewise, O(N^2) is "enn-squared", not "quadratic". I suppose "cubic" has fewer phonemes than "enn-cubed", but I think the latter term would still be more common.
Jul
26
comment Why is object-level privacy difficult to use as a paradigm, and why is it desirable?
...the data source could have the data split into multiple backing sections without exposing that fact (or the arrays themselves), and the destination could know that the helper class would never expose the array to the data source, but the helper class would still be able to use bulk-copy operations to move data in cases where the data source could accommodate that.
Jul
26
comment Why is object-level privacy difficult to use as a paradigm, and why is it desirable?
@Deduplicator: You're right; I oversimplified. Doing things properly requires a "trustworthy" class which is instantiated with data from one class object and can do specific actions in relation to another; in systems that support value types, such a thing can be pretty efficient and versatile. For example, if .NET included a suitably designed helper class for the purpose and had IReadableList<T> or a variant thereof support it, it would be possible for any implementation of that type to allow its contents to be quickly copied into an array in such a fashion that...
Jul
25
answered Why is object-level privacy difficult to use as a paradigm, and why is it desirable?
Jul
25
comment Why is object-level privacy difficult to use as a paradigm, and why is it desirable?
Even with object-level privacy, one could implement equal by having a method usesWriter(ostream *writer) and then equal(i_write_things const &other) { return other.usesWriter(this->writer);}.
Jul
25
comment Why don't languages include implication as a logical operator?
I remember IMP from DEC BASIC. I don't remember EQV. The operator I've often wished for would be "and not", which would promote the right-hand operator before negating it. Thus, 0xABCD12345678ul ~& 0x00200000u would yield 0xABCD12145678ul rather than 0x12145678ul.