29,749 karma · joined Sep 16, 2009 (17y ago) · 3,593 submissions
comment 15y ago · link · parent
int x = *p;
if (p == NULL) {
// p can't be NULL without having triggered
// undefined behavior in the first line, so
// this code is removed by the compiler.
return;
}
// ...
The fix is to stop dereferencing p before you know whether it's NULL or not: if (p == NULL) {
// Moving the check before the dereference
// avoids undefined behavior and resolves
// the issue.
return;
}
int x = *p;
// ...comment 15y ago · link · parent
The Curry–Howard isomorphism[1] would beg to differ. I think programming is much closer to math than this comment gives it credit for. In some sense, programming is even stricter than math. When doing math, you just have to satisfy your instructor or your reader. When programming, your program must run on a real computer -- there's no room for hand waving or imprecise arguments.
[1] http://en.wikipedia.org/wiki/Curry–Howard_correspondence
3455.
On Salvation(somethingaboutmaps.wordpress.com ↗)
1 points · by panic · 15y ago · discuss
comment 15y ago · link · parent
comment 15y ago · link · parent
Have you ever read the book QED? It's Feynman's best effort to explain Quantum Electrodynamics to a layman. In the book, he takes a genuine question about the nature of things (how does light work?) and answers it by "bringing up paper and arrows!" (I encourage you to read the book to see what I mean). Feynman disliked "explaining" nature with inaccurate and irresponsible metaphors. But arrows are the way it really is!
comment 15y ago · link · parent
comment 15y ago · link · parent
- each character will be two bytes (so, for example, char
lookup table you may have allocated needs to be
expanded from 256 to 256 x 256 = 65536 elements)
- that you would need to use wide char types (wchar_t
instead of char)
- that you would need to use wide string functions (like
wprintf instead of printf)
Unicode support involves more than just the minimum number of bits used per character.
Say you're writing a method to truncate a string to a certain length. What if your text contains a code point outside the basic multilingual plane, and each character can't be represented in just 16 bits? If you truncate in the middle of a character, the result will be an invalid string. What about combining characters? If you truncate in the middle of a combining character sequence, you'll end up with half-formed output (e.g., letters missing a diacritic). If you work with text, you should know this stuff!
comment 15y ago · link · parent
Robots.txt specifies a set of URLs that automated crawlers are not supposed to access. I'm not sure how this is "like robots.txt, but for humans".
comment 15y ago · link · parent
function f(x, y) { x = y }
a = new A()
b = new A()
assert(a != b)
f(a, b)
if (a == b) {
print('pass by reference')
} else {
print('pass by value')
}comment 15y ago · link · parent
The object of the BIGNUM BAKEOFF is to write a C program of 512 characters or less (excluding whitespace) that returns as large a number as possible from main(), assuming C to have integral types that can hold arbitrarily large integers.
See the third line of http://djm.cc/dmoews.html for more, including the (quite interesting, IMO) results.
comment 16y ago · link · parent
3470.
Optogenetics - New Light on The Brain(stanfordalumni.org ↗)
1 points · by panic · 16y ago · discuss
comment 16y ago · link · parent
comment 16y ago · link · parent
comment 16y ago · link · parent
Second, how would you solve priority inversion for general semaphores? With mutexes, you know what thread is holding the mutex, and can bump its priority correspondingly. With semaphores, there's no guarantee that the same thread that incremented the semaphore will decrement it later.