| Computing desk | ||
|---|---|---|
| < November 18 | << Oct | November | Dec >> | November 20 > |
| Welcome to the Wikipedia Computing Reference Desk Archives |
|---|
| The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
Hello, I'm currently doing a college seminar on the topic Special Effects in TV. When I googled, I came to know about 2 books by Bernard Wilkie - Special Effects in Television (1995), The technique of special effects in television (1971). But I couldn't find any digital version of these books anywhere on the internet, for the purpose of reference. Could anyone help me?--Joseph 05:20, 19 November 2016 (UTC)
Suppose I have an abstract List interface with multiple implementations:
struct List {
virtual int size() const=0;
virtual float& get(int)=0;
};
struct Array : List {
float *a;
int sz;
Array(float *p,int n) : a(p),sz(n) {}
int size() const {return sz;}
float& get(int i) {return a[i];}
};
struct Empty : List {
int size() const {return 0;}
float& get(int) {} // what goes here?
};
float sum(List &l) {
float ret=0;
for(int i=l.size();i--;) ret+=l.get(i);
return ret;
}
(In general, Array is much more complicated, so that Empty e; cannot trivially be realized as Array e(0,0);.) What should Empty::get() do? It's valid the way it is; like for a real array of size 0 (new float[0] is valid!), calling Empty::get() with any argument at all should be undefined behavior. The undefined behavior (from flowing off the end) doesn't happen, because sum() knows better than to actually call Empty::get() at all. But there will be an egregious warning. There are a variety of relatively obvious options, but none of them are very good:
float& get(int)=delete; (This is ill-formed: overrides of non-deleted functions can't be deleted.)float& get(int);. (But then you fail to link, even if no one actually calls the bad function.)float Empty::get(int) {return 0;}. (But the reference can be important.)float& Empty::get(int) {float f; return f;}. (But that'll still be a warning.)float& Empty::get(int) {return *reinterpret_cast<float*>(0);}. (No warning from the compilers I tried, but I'd not be surprised if one were added. Also, it's ugly.)float& Empty::get(int) {static float f; return f;}. (But allocating memory for nothing is dumb.)float& Empty::get(int) {throw 0;}. (But that's not undefined behavior: someone could catch it.)float& Empty::get(int) {throw;}. (But that's not undefined behavior: you just call terminate() if there's no current exception.)float& Empty::get(int) {std::abort();}. (But that's not undefined behavior.)What's the canonical way to write "no, really, this is supposed to be undefined behavior"? --Tardis (talk) 05:28, 19 November 2016 (UTC)
a.get(-1) or a.get(a.size()) on a valid Array a variable is UB, too, and you do nothing to handle it. Undefined behavior is just undefined, i.e. a program can do anything—it can produce some reasonably looking result, it can crash or proceed with some garbage data...n in Array::get(int) and throw some exception or raise a signal in case of invalid call; then you just make Empty:get(int) to do the same. But, as you noted, that is a defined behavior. AFAK there is no way to define in the code an undefined behavior...// Watch out, UB here. --CiaPan (talk) 09:30, 19 November 2016 (UTC)
a.get(-1) is UB; it is exactly that "natural" UB (Array::get() is UB exactly when you shouldn't be calling it) that I'd like to express in Empty::get(). The problem there is that all calls should be UB, and the compiler quite reasonably warns about a function that always results in UB. (This is not a reasonable thing to want, except in the case of a "poisoned" virtual override like this.)float& Empty::get(int) {return get(0);}. This also gets no warning (from G++ 5.4.0 with -W -Wall), and compiles at -O2 or better into an infinite loop(!) by tail recursion elimination. (From a practical perspective, I'd rather have a signal, but that's why they call it undefined; I can write abort() if I really want to.) --Tardis (talk) 15:38, 19 November 2016 (UTC)
everyone (Mozilla, Microsoft, WolframAlpha) seems to have some online program going on to teach people how to code. is it some weird social engineering thing? It's like DOSAAF, seriously. is it to make people think like machines? or to press wages? but the West can't out-cheap India. Even if everyone was a coder, wages can't fall below housing and food. This is the limiting factor, not the supply in labor. Asmrulz (talk) 12:52, 19 November 2016 (UTC)
Why do they have something that's neither a variable nor a string? Couldn't we just use a string instead, like "abcd" in Python, when you don't want to execute something? And, use something like the pythonian eval("abcd") when you want to run it? — Preceding unsigned comment added by 123abcnewnoob (talk • contribs) 13:18, 19 November 2016 (UTC)
eval, and you aren't an expert and understand exactly why using it is necessary in your situation, you're probably doing Bad Things. Read . Chances are you've fallen into the XY problem trap, where you don't understand how to do something the Right Way but managed to figure out that if you kludge together some code dynamically and eval it, it seems to do what you want. --47.138.163.230 (talk) 01:03, 20 November 2016 (UTC)