I'm a little bit slow with the low level stuff. Could someone explain what's so horrific about this code?
For one thing, he's using assembly of one type of machine and expects it to work on different type of machine. He confuses Linux as a machine abstraction and demands that Cygwin running on Windows to be the same. For the low level mess, he sets the stack frame pointer to a uninitialized heap-allocated buffer which contains God-know-what garbage. When main() returns, it pops its return address from the stack frame poi…
Your code should be taken out back, lined up against a wall, and machine-gunned
31–40 of 76 posts
Re: Your code should be taken out back, lined up against a wall, and machine-gunned
#32Earlier quoted context omitted.
I think it's because his indignant demand of the Cygwin team to fix this "bug" and make it work for him. Basically it's the attitude that I know my way is the right way, now fix the platform so that my program runs.
Yeah, but blunt brevity and "go read X instead, you're going about it wrong" would have been better for everyone involved.
We are just humans. Totally unrelated input might result in a change on the output.
Re: Your code should be taken out back, lined up against a wall, and machine-gunned
#33Earlier quoted context omitted.
I think it's because his indignant demand of the Cygwin team to fix this "bug" and make it work for him. Basically it's the attitude that I know my way is the right way, now fix the platform so that my program runs.
I don't see any demands in the original mail: http://www.cygwin.com/ml/cygwin/2005-08/msg00504.html He questions whether it "should be fixed" in Cygwin, a perfectly reasonable request, and he fully admits that he isn't sure whether it's a problem in Cygwin or not.
His reference to Linus doing the same thing in kernel (not) sounds very much like a smack response.
Also he claims he knows what he's doing since he has done the same thing in DOS so when it's clear that he has no clue of what's going on just irrates people.
Re: Your code should be taken out back, lined up against a wall, and machine-gunned
#34While I always enjoy a good rant, I don't see why it had to be so vicious and insulting. Yeah, the guy's clearly pretty confused (if he wanted to do these kind of tricks, I'd try to use setjmp, fiddle with the structure, then longjmp to it), but there's no reason to be mean about it.
Re: Your code should be taken out back, lined up against a wall, and machine-gunned
#35I'm a little bit slow with the low level stuff. Could someone explain what's so horrific about this code?
I personally haven't done anything with coroutines but looks like from a low level perspective, ultimately what he is trying to do is not insane… aka do some form of task switching. Arguably, he shouldn't be doing this by himself and he should've resorted to something that is already available. Just a quick look at (http://en.wikipedia.org/wiki/Coroutine#Coroutine_alternative...) should've been sufficient. Yet.., maybe he had some reason to try and do it himself. Looks like at the end he managed to figure out what he wanted to do.
Re: Your code should be taken out back, lined up against a wall, and machine-gunned
#36While I always enjoy a good rant, I don't see why it had to be so vicious and insulting. Yeah, the guy's clearly pretty confused (if he wanted to do these kind of tricks, I'd try to use setjmp, fiddle with the structure, then longjmp to it), but there's no reason to be mean about it.
Because he had the same attitude with this guy: http://bugs.php.net/52435
From the comments: I get this problem too. It only seems to happen if your IQ is less than 70, though.
Re: Your code should be taken out back, lined up against a wall, and machine-gunned
#37Earlier quoted context omitted.
C allows implict casting of void* to any other kind of pointer. Hence, you never need to cast the return from a malloc if you're storing it in a pointer. C++, however, does not allow this. So, if for some reason you're calling malloc rather than new in C++, you need to cast.
You are not the poster who said "casting malloc's return is evil", so perhaps you don't agree with that statement, but I don't see how either of the points you make lead to the conclusion that it is "evil". You say that since void* is implicitly cast to all pointer types, you never need to explicitly cast it, but why would that make an explicit cast evil?
Re: Your code should be taken out back, lined up against a wall, and machine-gunned
#38Why was he complaining about the stack pointer first? Isn't this line: st1 = (void *)malloc(5000) + 5000; completely invalid too? You can't (I think it's undefined) increment a void pointer.
Actually, since st1 is a char* and the sizeof char is 1, that is a valid declaration. It just probably isn't doing what the writer expects. It allocates 5000 bytes and then moves the pointer to point at the very last byte. edit: Though free()ing it would not work so well until you move the pointer back to the beginning of the 5000 bytes.
Re: Your code should be taken out back, lined up against a wall, and machine-gunned
#39Earlier quoted context omitted.
C allows implict casting of void* to any other kind of pointer. Hence, you never need to cast the return from a malloc if you're storing it in a pointer. C++, however, does not allow this. So, if for some reason you're calling malloc rather than new in C++, you need to cast.
You are not the poster who said "casting malloc's return is evil", so perhaps you don't agree with that statement, but I don't see how either of the points you make lead to the conclusion that it is "evil". You say that since void* is implicitly cast to all pointer types, you never need to explicitly cast it, but why would that make an explicit cast evil?
Re: Your code should be taken out back, lined up against a wall, and machine-gunned
#40Earlier quoted context omitted.
For one thing, he's using assembly of one type of machine and expects it to work on different type of machine. He confuses Linux as a machine abstraction and demands that Cygwin running on Windows to be the same. For the low level mess, he sets the stack frame pointer to a uninitialized heap-allocated buffer which contains God-know-what garbage. When main() returns, it pops its return address from the stack frame poi…
Uh, actually, his original program ( http://www.cygwin.com/ml/cygwin/2005-08/msg00542.html ) did restore the stack pointer before returning from main. He "wanted to cut [the example's size] down for the sake of the mailing list", so he left that bit out.
But the real issue is that what he's doing is completely unnecessary, because you could manage multiple stacks yourself using ordinary C data structures and ordinary C code. Evidently he thinks he's gaining some kind of speed advantage by doing things this way, but the risk is very high versus the gain. This kind of optimization may have worked OK on a DOS machine, but it's neither safe nor obviously faster to do things like this on a modern CPU and OS.