« first day (172 days earlier)      last day (4794 days later) » 
00:00 - 18:0018:00 - 00:00

6:02 PM
@ChrisBecke Not so. Leave off "member" - a void * is not necessarily able to hold a pointer to any function, member or otherwise. In the case of a member function, it's pretty much guaranteed it won't, whereas with a global function, it may or may not be. This is true in C as well as C++ (though, of course, the part about member functions clearly just doesn't apply to C at all).
 
I thought void* could hold any pointer in C
 
@ChrisBecke You were wrong. It can hold a pointer to any object (i.e. data type), but not necessarily a pointer to a function.
 
oddness
 
if you edit a question do you earn rep?
 
@BlackBear no you do not, at most you earn a badge or so
 
6:11 PM
@Tony before reaching 2k rep I earned 2 or so, I think
 
@BlackBear oh ok
 
You earn rep for accepted suggested edits AFAIK.
 
got it :) thx
 
7:16 PM
I am fairly sure I can't, but just to make sure. Are you able to access a 1D array like it was a 2D array? Again, fairly sure you can't
I know that I can access a 2D array like a 1D, but is there a sensible way to go the other way?
 
of course :)
x = number % width
y = number / width
assuming a row major ordering
 
erm... what I mean is int data[100]; what cell should data[1][10] access with in the original array
I am sure that answer is, you can't
 
@thecoshman Erm, simply rewrite data[y][x] as data[y*width + x]?
 
7:47 PM
@FredOverflow but my point still stands that you can't access a 1D array using 2D notation right?
 
@thecoshman You can if you know the width at compile-time:
int a[100];
typedef int (*view2D)[20];   // a 5x20 view
view2D b = reinterpret_cast<view2D>(a);
b[1][10] = 42;
 
@FredOverflow strange code dude, but no, width is unknown at compile time.
So with out doing some overly complex arseing around, it can't be done
good :D
 
True 2D arrays only work if you know the width at compile-time.
Of course, you could still write a wrapper class that knows the width at runtime and provide an operator[] overload.
@thecoshman There you go ;-)
You can replace the 20 in that example with any int expression, it does not have to be known at compile time.
 
8:24 PM
Here's another example with the width known only at run-time, by overloading operator[]. See: stackoverflow.com/questions/2216017/…
 
8:57 PM
@FredOverflow neat
 
@FredOverflow Now that's pretty cool :)
 
9:31 PM
Is it possible for a compiler to check that a recursive function terminates, in the general case? Or would that solve the halting problem?
 
@GMan well it sounds pretty impossible to me
isn't that the very definition of the halting problem? when does it terminate?
 
It's when does a program terminate. I guess if you just define a function to be a program, then perhaps.
But I think the property of programs in the halting problem that make it undecidable is that programs can query if programs halt.
 
Well, program in C++ is a main function. :P
 
But C++ functions cannot query the compiler.
 
@GMan but how would a compiler know if a function halts? it would have to be able to "reason" about what it's doing and whether it's terminating condition would ever be met
 
9:37 PM
And subprogram is a synonym for the function, I believe.
 
@PiotrLegnica In our terms, sure but does that hold for the more "rigorous" definition?
 
maybe an AI enabled compiler, but since I'm no expert or have not enough knowledge about compilers, I have no idea
 
Oh, you know what, I asked the wrong question. Yes, it would solve the halting problem.
 
@GMan I think I can agree with you on that
 
I'm not much of a theory man. ;)
 
9:39 PM
I meant to ask (was thinking) can the compiler prove it doesn't halt? (That is, it's not necessarily to say it does halt.) I think that's possible.
 
You could detect obvious infinite loops, but not always.
 
That is, the two outputs are not "yes it halts" and "no, it doesn't halt" but instead are "it doesn't halt" and "i dont know"
 
A loop with a constant condition that evaluates to truth and no external jumps inside is obviously infinite.
 
Yes.
I think the algorithm would be to check if the branches that allow a non-recursive return can ever be true.
If at any point there isn't enough information to tell, return "I don't know".
 
10:04 PM
@GMan that one is trivially true. Of course it can, when you allow it to just fall back to "I dunno" whenever it fails to prove that it doesn't halt
you'd just have to come up with one single program where the compiler correctly deduces that it doesn't halt, and then it can answer "don't know" to everything else and it'll still satisfy your stated requirement
 
@jalf Hm, but it can't say "I don't know" if it can prove it halts with other means.
 
What do you mean?
 
I dunno. I don't know the terms to say what I'm thinking. :(
 
You can always prove that it doesn't halt, if you're willing to wait sufficiently many multiples of the universe's total lifetime, even for a NP-complete problem
er, you can always answer the halting problem, I guess I should say
or you can always prove that a non-halting program doesn't halt
hard to prove it for one that does halt :D
 
lol, I'm confused.
 
10:09 PM
lol
well, what I'm trying to say that NP-complete problems such as the halting problem aren't literally speaking undecidable
 
In finite time?
 
you never said anything about finite time ;)
 
I keel you.
 
anyway, if you want the compiler to accurately detect every instance where a program doesn't halt, that still sounds like the halting problem to me. And if you allow it to go "I don't know", then it becomes trivial unless you set up some specific criteria for when it is allowed to say "I don't know"
 
Hm, makes sense.
 
10:14 PM
like I said, otherwise you can just return true if the program contains something obvious like for (;;);, and "dont know" for everything else
which technically satisfies your requirements, but isn't very useful
 
Yeah.
 
what is this for, btw?
 
Nothing, just thought "I'd be interesting if compilers had to diagnose infinite recursion. But that solves the halting problem, any simplifications possible?"
But like you said, we can make any arbitrary simplification.
 
by George! I think I just got why unions as so handy!
 
And now for something completely different. :)
 
10:17 PM
@GMan <blush face>
 
anyway, didn't litb or someone find a paragraph in the C++0x spec saying the compiler was allowed to optimize out infinite loops? That'd make it tricky to ever answer anything other than "I don't know" ;)
@thecoshman how so? For type-punning?
 
Wait, what? How is infinite loop a candidate for optimising out? :/
 
@PiotrLegnica I just remember seeing the SO question. It was only a side-effect free infinite loop
I guess the logic is that if there are no observable side effects, the compiler could optimize out a single iteration, and if it can optimize out a single iteration, why shouldn't it be allowed to do that an infinite number of times? ;)
 
@PiotrLegnica @jalf For optimization reasons, loops are assumed to end. (Or something like that.)
 
or more concretely, "if your program never actually does anything, who cares whether or not we terminate it early by removing the infinite loop?"
 
10:20 PM
@jalf mostly to avoid having overload a function to explicitly take multiple types, it can just take a union. The types with in the union would be specified as ones that all have a common "type" property, thus the function can know how to deal with certain things based on "inputUnion.type"
 
39
Q: Optimizing away a "while(1);" in C++0x

Johannes Schaub - litbUpdated, see below! I have heard and read that C++0x allows an compiler to print "Hello" for the following snippet #include <iostream> int main() { while(1) ; std::cout << "Hello" << std::endl; } It apparently has something to do with threads and optimization capab...

@thecoshman Poor man's boost::variant. :)
 
wait, are you guys saying that if I did write while(1) in 'old' C++ the compiler is meant to let that actually happen?
 
@thecoshman in a C++0c compiler, it'd be a proper infinite loop, as far as I know
 
wouldn't while(1); loop forever?
 
@GMan why reinvent the wheel? or if boost got there first, why not use the standard version?
 
10:22 PM
@Xaade Yeah, that's why it's called an infinite loop.
 
@Xaade thats' the point. It would, but in C++0x, the compiler is allowed to assume that it doesn't
 
@thecoshman Try putting a std::string in your union.
 
@thecoshman I'm pretty sure unions were invented before boost ;)
 
I get that much.
However, my point is that, you're not optimizing, you're changing expected results.
 
@GMan I'm not saying I want to use them my self, just that I get the little blighters :P
 
10:23 PM
My first bugcheck in Windows 7, woo!
 
Optimization is no longer a tool, it's now a babysitter.
 
@Xaade every optimization does that. Your expected result when executing the code naively might be "it runs for 10 seconds, and then prints a result". Then you optimize it and now it prints a result immediately.
 
@thecoshman Then good work. :)
 
so C++0X can specially handle an infinite loop so that it runs 'better' going on the assumption that it there for a reason
@GMan that I'm not going to use them or that I get them?
 
@thecoshman Latter.
 
10:25 PM
Any hoops... dissertations don't write them selves... sadly :C
 
@Xaade keep in mind that we are only talking about infinite loops with no side effects. In other words, loops that have no expected result, so how can it matter that the compiler skips them?
 
Optimizing should avoid changing the end result. It can change what the processor does to accomplish the code, but it you're there removing the infinite loops that programmers put in by mistake, that's babysitting.
 
@Xaade it's more like saying that a loop which doesn't terminate, and which has no observable side effects, is undefined behavior
so the compiler can do with it what it likes
the optimizer can change the result of dereferencing a null pointer too, by removing the operation entirely if it's not necessary
 
@jalf because if while maintaining, someone comes in and expects the loop to do something, and puts code it in, he just broke your program. Or worse yet, what if someone puts code in the loop by mistake.
 
@Xaade What's wrong with babysitting?
 
10:27 PM
@GMan Makes programmers more sloppy.
 
@Xaade Justification being?
@Xaade You must dislike type-checking, then?
 
@GMan I already have enough frustration with people leaving in compiler warnings if they aren't affecting execution.
@GMan type-checking doesn't make me sloppy, it makes the code more verbose.
 
After all, my compiler scolding me for operating on data incorrectly is babysitting, and babysitting makes me sloppy. So type-checking is out.
@Xaade: Really? The trade-off isn't worth it?
 
@Xaade you just don't realize how much the optimizer already changes the results of your programs
 
@GMan But they are used differently. The compiler isn't giving an error when it sees an infinite loop that does nothing. The compiler is ignoring it.
 
10:30 PM
@Xaade that's your assumption
 
CPU does magical things to the code at runtime, too.
 
@PiotrLegnica Good point.
 
as I said before, the optimizer can already optimize out operations which would normally cause a crash. It's already doing all the things you hate
 
Ok, well I'm getting watered down and strawmanned here.... so there's no point.
 
an optimizer which didn't do that would be pretty useless
 
10:31 PM
@jalf Which has resulted in me turning it off in some cases. People doing stupid stuff that eventually results in UB.
 
@Xaade I'm more interested in what you think about type checking. You don't like it?
 
Like having an argument change and reference twice in a function call, assuming the compiler resolves the arguments in order. Causing bugs in release but not in debug..... making it harder to debug my app.

Yeah, I don't like that.
@GMan I didn't say that
 
also note that they're not saying "feel free to disregard what the code says", but simply (as I read it), that a loop which has no side effect and never terminates, is simply UB. The compiler may assume that the loop terminates, so if it doesn't, all bets are off
 
@Xaade Okay. You said it's verbose, most people use verbose pejoratively.
 
@Xaade on the other hand, it makes your app run faster. You can't have it both ways ;)
 
10:33 PM
@jalf Ok, I missed the part where it was classified UB. That changes everything.
 
@Xaade well, it's not spelled out specifically that it's UB, just that "the compiler may assume" that the loop terminates. As I read it, that means that if it doesn't terminate, it's UB
 
@jalf Again, I've turned it off in an app where people don't know how to use it wisely. For personal use, I'd leave it on, but apparently this app can't be trusted.
 
but that's just my interpretation
 
@jalf It's UB. When the standard says "make this assumption", if you break it that's UB.
 
I'd have no arguments against declared it UB. That would be preferential actually. Then I don't have programmers removing all code from while(1); loops and leaving the while code in assuming it just worked.

If it defined the code to be skipped and not UB, I'd have to say that's a bad idea.
 
10:35 PM
but yeah, I'd be iffy about it if it was just an optimization, but when they call it UB, it makes sense. It's a nonsensical operation, so why should the compiler be obligated to generate specific code for it?
 
What I mean to say, I don't like the possibility of programmers changing this: while(1) { dosomething; break; } to while(1); and not remove the while, relying on C++ standards that says the compiler will ignore that line of code.

That's not a good optimization. That's encouraging bad programming.
Which is different from type-checking. Type-checking is essential to my programming style. It doesn't make sloppy code.... it cleans up sloppy code.
 
@Xaade It doesn't encourage anything. It enables it, sure, but that's nothing new in C++.
 
@GMan Sorry, that's correct.
Like I said. I don't like it. Doesn't mean I'll stop using C++, or that I will even care beyond this moment.

However, I don't like it.

Isn't fair enough to not like something and have a good reason why?
 
Yup.
 
10:51 PM
Anybody knows a way to set a preprocessor definition in xcode based on environment variable?
 
11:03 PM
@Eugene I'm in that sort of delirious state where the only answer I can think of is 'magic'
 
however as long as you access a volatile object before an endless loop, you can still do while(1) ;
 
With xcode it is always either magic or "why would you ever want to do that?!"...
 
00:00 - 18:0018:00 - 00:00

« first day (172 days earlier)      last day (4794 days later) »