« first day (371 days earlier)      last day (4578 days later) » 

12:22 AM
 
12:41 AM
@AlfPSteinbach True.
 
1:13 AM
@awoodland It's doable but there is no standard facilities to help.
@RMartinhoFernandes Nice rewrite.
 
 
2 hours later…
cpx
3:27 AM
hmm this looks similar to the situation i had yesterday with casting
void func() {}
void(*fp)() = func;
(********fp)();
de-reference as many as time you want!
 
3:45 AM
This video is so wrong. It shows pictures of the actor named "Andrew Koenig" who died a while ago. Some of the pictures turn out to be the C++ Koenig. Oops.
 
cpx
4:17 AM
@StackedCrooked nice!
For youtube viewers here :)
 
Yeah, but the full 19 min interview is not available on Youtube (I think).
 
 
1 hour later…
5:30 AM
Is this preferable to NoScript (or to no NoScript, as is my case)? eff.org/https-everywhere
 
6:21 AM
@RMartinhoFernandes power communications... :-)
 
 
2 hours later…
8:33 AM
Hi
 
hi. can you explain chinese rings puzzle for me?
 
me ? but you are the expert here
can anyone here help me recover my partition table ?
 
oh i'm sorry i don't know how. but probably more people can help if you tell which OS
 
I had both windows7 and ubuntu 10.04
 
sound like windows was original OS and ubuntu was installed in virtual thingy?
or was that multi-boot?
 
8:43 AM
no a dual boot
yes
grub2
I don't even know how this happened
 
Can you diagnose the problem? MBR issues?
 
actually my partition table is complety gone but the partitions are there
so I can't boot
 
I don't think I know of a tool to 'detect' partitions then.
 
I'm trying a tool named testdisk in a ubuntu livecd
I have got the windows boot manager to start at least
 
9:17 AM
i found a javascript sim of the chinese rings.
i thought, aha!, the handle can be removed! allowing rings to go on or off at either end
but then i don't understand the 6th step, going forward here, britton.disted.camosun.bc.ca/patience/patience.htm
how is that physically possible?
am i being extraordinarily stupid when i don't understand this?
 
10:19 AM
@LucDanton - I asked that tuple into function pointer thing as a question in the end since I've still not got a nice solution: stackoverflow.com/questions/7858817/…
 
10:51 AM
@awoodland I'll answer some time then.
I still have no idea why you mention std::forward though.
Actually Johannes showed the technique I was about to demonstrate.
 
11:11 AM
@CatPlusPlus Please don't write a separate class for every kind of shape ;)
 
@LucDanton - until last night I thought std::forward was a type
which implied I could use it as a member, but I was way off base
 
@awoodland F12 is your friend, if you have Visual Studio.
 
@FredOverflow - I'm using emacs with AutoComplete mode (via clang for C++)
 
@awoodland Okay, then the C++ standard is your friend, I guess ;)
 
hmm that would be quite a nice (but tricky to do) emacs hack - jump through the related pages of the standard in another buffer
 
11:24 AM
@awoodland Lol, funky. Note that decltype(T) doesn't work where T is a type.
 
@LucDanton How about decltype(declval<T>())? :)
 
@FredOverflow Damn, there goes half my code.
 
What is the most efficient representation of a Tetromino?
 
template<class Seq, class T, class R>
void apply(Seq& sq, R (T::*f)()) {
  typename Seq::iterator it = sq.begin();
  while(it != sq.end()) {
    ((*it)->*f)(); //shouldn't this be ((*it).*f)(); if Seq is vector and contains objects
    it++;
  }
}
 
Can we see the client code?
 
11:38 AM
@FredOverflow no client code needed
 
It's a lot easier to test your assumptions with client code.
 
apply(vector_of_objectA, &objectA::foo);
 
So, did the client code compile?
 
Is it possible to make a function that runs an .exe file? If so, how? And if it's a bad idea, why?
 
struct X
{
    void print()
    {
        std::cout << "hello\n";
    }
};
int main()
{
    std::vector<X> vec(5);
    apply(vec, &X::print);
}
@MrAnubis This code took me one minute to write. It turns out that you were right, it should be .* instead of ->*.
 
11:45 AM
Why not std::function?
 
@CatPlusPlus How would I know?
@SSight3 What do you mean?
 
@FredOverflow Say I have a DownloadImage.exe that takes an argument to a website (to download the image from), how would I call that in C++?
 
@FredOverflow here it is ideone.com/iZZYU
 
@MrAnubis vector<Gromit*> is a vector of pointers, in that case ->* is correct.
@SSight3 click me
 
@FredOverflow can you also help me with this error ideone.com/FkhuR
 
11:51 AM
system is silly. You need an OS API, like exec on *nices, or CreateProcess on Windows. Or use Boost.Process or a different wrapper library.
 
@MrAnubis int f(){} should either be void f(){} or int f(){return 42;}
 
@FredOverflow thanks but still comes the error ideone.com/QdaWT
 
Also, ff.push_back(ff); should be ff.push_back(bar);. You are trying to push back a vector into itself :)
Or just leave out the bar variable and write ff.push_back(Fred());.
By the way, warning: unused variable ‘bar’ was a good hint by the compiler. Never ignore warnings!
 
@CatPlusPlus "ShellExecute(GetDesktopWindow(), "open", "c:\myTestFolder\myfile.exe", NULL, NULL, SW_SHOWNORMAL);" Was given as an example, but how are arguments passed?
 
@FredOverflow Thanks a lot , you were so right , i need to get some good book like c++ primer etc
 
11:54 AM
folks
 
HINSTANCE ShellExecute(
  __in_opt  HWND hwnd,
  __in_opt  LPCTSTR lpOperation,
  __in      LPCTSTR lpFile,
  __in_opt  LPCTSTR lpParameters,   // <--- hint hint!
  __in_opt  LPCTSTR lpDirectory,
  __in      INT nShowCmd
);
 
int f() { } is fine AS LONG AS YOU DON'T CALL IT
 
But is is called.
 
@FredOverflow Hint noted. Char *?
 
@MrAnubis C++ Primer is an excellent choice.
 
11:56 AM
in fact int main() { return 0; return f(); } is fine TOO!
 
@SSight3 Depending on Unicode and other stuff I'm not too familiar with, LPCTSTR may or may not be a char*.
 
Long Pointer to Const Templated STRing
the "Templated" means it may either be C string or Wide string
 
The w being wchar_t?
 
@FredOverflow Okay, thank you. Do you know if the lpFile argument is relative (to the calling processes' position) or absolute?
 
11:59 AM
no
 
it shall point to the VirtualAddress
 
Is there any way to determine the success/failure of the called executable?
It seems to be silently failing (or succeeding?) but it's hard to tell.
 
cpx
Hm, F12 key for Edit.GoToDefinition set as global but doesn't work in VS.8.0
 
@SSight3 you can check its return code
 
cpx
@SSight3 I think ShellExecute returns < 32 for sucess.
 
12:09 PM
or of course, add some logging to the called executable. :)
 
Cool, thanks.
Apparently, ShellExecute's return type is a pointer
"ISO C++ forbids comparison between pointer and integer|"
 
@SSight3 why would you want to compare the pointer to an integer?
oh, never mind
 
ShellExecute's return type is apparently a pointer. Sorry, SO acting up argh.
 
Did you read the function's documentation? :)
> If the function succeeds, it returns a value greater than 32. If the function fails, it returns an error value that indicates the cause of the failure. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. It is not a true HINSTANCE, however. It can be cast only to an int and compared to either 32 or the following error codes below.
but note that this only tells you whether the ShellExecute call succeeded. It does not tell you whether the process you launched returned an error when it finished
I think you'll need to use CreateProcess or similar to get a handle to the launched process, and check its return code
 
@jalf That would explain why it returns success but there's no file being created.
 
12:21 PM
yeah, it basically does the same thing as when you double-click on a file. It starts the program, but nothing else. It doesn't wait for the process to terminate
 
Every time I look at the WinAPI, I stop wondering why I hate it so much.
 
:)
it's an easy API to hate
 
Now I'm looking at how to close the handle, waiting, deadlocking, calls that hang and event queues. Only the WinAPI could be this complex for something as simple as calling a .exe.
I just want to call a freakin' .exe! I don't want to have to call one billion processes that then eventually permit me to call an .exe that might just fail anyway!
 
WaitForSingleObject, I believe
and then CloseHandle of course
 
9
Q: How do I call ::CreateProcess in c++ to launch a Windows executable?

jm.Looking for an example that: Launches an EXE Waits for the EXE to finish. Properly closes all the handles when the executable finishes.

 
12:30 PM
if it's any help, I'm still wrestling with the MMX instruction set, which is at least as painful
 
@jalf It's both as reassuring there are others, and disappointing such a problem has never been resolved.
Success! But now it appears that the ArgV arguments are incorrectly offset.
 
@jalf - I thought SSE superseded MMX in all respects and didn't double up on the FPU registers?
SSE3 added integer vector instructions
 
@awoodland nearly every respect. My problem is that I need to emulate 64-bit integer operations, so a 128-bit register doesn't really help me that much :(
I did spend some time fiddling with converting my code to using SSE instead, but put that on the back burner a bit. Didn't really seem worth the trouble
 
I took the opposite approach last time I cared and ignored MMX entirely (add with two 64bit ints packed into a 128bit register: msdn.microsoft.com/en-us/library/d944hwxx.aspx)
 
SSE2 supports 64-bit int arithmetics? :o
 
12:42 PM
yeah
 
Can I ask a crazy question?
Can main return a std::string? And should I do that?
 
why didn't I notice that before? I've gone over the list of SSE2 intrinsics a million times
for everything? comparisons, shifts and all?
@SSight3 main returns an int
 
@SSight3 - main returns int and only int
 
always an int, and nothing but an int :)
 
B-b-b-but void main?
 
12:43 PM
@SSight3 is an error :)
 
You can use int main() or int main(int, char**), but never void main... ;)
even if some compilers accept it
 
Okay, seems to reject my void main.
 
if you want to return a string I'd suggest doing it via a pipe or something
 
@awoodland ah right, there's no < for 64-bit ints. I knew it wasn't that simple
 
12:45 PM
or shared memory segment
 
guess SSE2 won't solve the problem after all then :/
 
which instruction are you looking for? r = min(a0, b0), min(a1,b1)?
or an actual boolean operator<
 
@SSight3 have you checked out ShellExecute & friends?
 
@AlfPSteinbach Yep. ShellExecute doesn't return process status. It works but I'm not sure if it's worth the hassle.
 
the only problem with that, as i recall, is that it has silly result value, i think like 16-bit Windows LoadModule or something.
 
12:54 PM
The .exe idea that is.
 
well, to close the handles, make small classes
 
@awoodland Operators <, <= and ==
or intrinsics making it easy to emulate them
 
or you can use Petru Marginean's ScopeGuard
by "make small classes" i mean small classes with destructors :-)
because then you can treat errors by throwing exceptions
makes the whole thing simpler
generally
note for ScopeGuard: if you use Visual C++'s modify-and-continue support, then you need to replace the original source's standard __LINE__ with Visual C++-specific __COUNTER__. i don't know why but Visual C++ fouls up the __LINE__ result when edit-and-continue option is present. Or it used to.
 
@AlfPSteinbach I think last time I saw edit-and-continue actually work was in VS2003. I was starting to assume its continued existence was an urban legend
 
there is one main reason to use ShellExecute instead of CreateProcess, and that is that the latter, in spite of originally being the lower level, doesn't handle modern User Account Checking well, it sort of barfs as I recall
 
1:00 PM
does edit-and-continue refer to debugging?
 
@jalf huh? can't say I have used it at all. but I recall it was introduced in Visual C++ 6.0 and has been annoying ever since
@JohannesSchaublitb yes
 
@JohannesSchaublitb yeah, the ability to break in the debugger, modify some code, and then have the changes immediately compiled so you can continue debugging
 
hmm
how does that work
 
just doesn't work very well in practice
@JohannesSchaublitb for the most part, it doesn't
 
edit and continue works pretty well for .net languages (particularly vb), but i don't think i've ever seen it work for c++
 
1:02 PM
isn't that as complicated as "export" ?
i mean they have to merge the new source with the binary code running somehow
how do they know what binary code to update
 
it's the debugger
 
@JohannesSchaublitb well, as long as you only modify functions that aren't in the call stack, it's kind of doable
 
the debugger has sort of very intimate knowledge of the machine code
 
obviously, if you make too big changes it just gives up and goes "stop debugging and recompile properly"
 
1:04 PM
so it's just marketing
 
@JohannesSchaublitb no, it's a debugging feature
 
GDB can do that too
 
in .net, you can actually change the line of code at the breakpoint, in the caller, the caller's caller, etc as well. it's pretty spiffy, really, but i can't say i've used it enough to matter
 
all you need is a good GDB client that tells it what part of the code to rewrite
 
@JohannesSchaublitb no, not at source code level
 
1:06 PM
GDB knows what code range a given function covers
so if the IDE changes the function it can request GDB to update its machine code
 
@JohannesSchaublitb so why is it "just marketing" when MSVC supports the same? ;)
 
gdb won't support editing and recompiling a function while the program is running.
oh, it does?
 
GCC will recompile it
not GDB
and <your IDE+ you> will edit it
 
i think that's vaporware ;-)
 
@AlfPSteinbach I like the idea. Whilst I don't use the particular method used there, I do something similar where dynamic and file classes are expected to delete/close their contents when they go out of scope.
 
1:08 PM
yeah, well. VS being an integrated development environment, it'll do all that without you having to worry whether it's the debugger, compiler, or editor :)
 
ah, you found it
 
but VS can only do that when the function is not in the call stack?
 
depends on the language, it seems
vb, it's a lot more flexible. c++, i've never even tried to make it work, so i couldn't say
 
@JohannesSchaublitb I'm not sure of the exact limitations, but the VS IDE can only automate it for you when the scope of your changes are limited
 
but someone's said no
 
1:11 PM
We're not talking about the underlying debugger, which is much more powerful than what is exposed through the IDE, or the underlying compiler
we were also merely describing a feature of MSVC, not trying to get into a pissing contest about whether or not it can do something that GDB can't
 
GDB is much better than VS's debugger IMO
 
so I'm not really sure what you're getting at
@JohannesSchaublitb better at what?
 
it has lots of fine tuning features
 
what should a debugger be fine tuning?
 
@jalf presumably at debugging
 
1:13 PM
VS's debugger is a hell of a lot more accessible and user friendly than GDB. And it doesn't crash as often.
 
that too. :)
 
And if I want more power, I've yet to find a feature of GDB than windbg can't do
 
gdb doesn't crash
 
oh, I must have been dreaming then
hallucinating, perhaps
 
1:14 PM
but again, no one here were actually saying "GDB sucks and the MVCS debugger is awesome"
 
lol
yet
 
I'm sorry if it hurt your feelings, but you asked what edit-and-continue is, and we answered. No one, except you, had any interest whatsoever in comparing it against GDB's capabilities
 
why would it hurt my feelings if you summarized the last 20 minutes of chat?
@jalf I agee I asked that. And I agree I was the one who compared it with GDB
 
you sound like it's extremely important to you to establish that GDB is superior in every way
as if you personal honor was at stake, or something
anyway, I'd better get back to beating MMX into submission
 
where can I sign?
lol
noone noticed I was actually trolling
 
1:16 PM
or the reverse, quite possibly
so far, MMX seems to be winning
@JohannesSchaublitb er, you think so?
 
@jalf except me of course
and maybe except the other N-3 people in the chat room
 
@JohannesSchaublitb Try again. It's really not difficult to spot when someone is trolling
 
...Only SO users can get worked up over semantics...
 
I just expected more of you
 
@jalf it's not difficult to spot when someone is trying to look right when he was proven wrong before
lol
 
1:19 PM
anyway, have fun all. The debugger is calling out for me
 
if you need any assistance I can install GDB on your box if you want
 
;)
 
Real coders don't need debugging tools.
...I think.
So you're both mostly wrong.
 
one of my friends sprinkles over his code statements of the form LOG("This should not happen!"); return NULL; LOG("Now shutting down!!"); // TODO: BUG IN THIS CODE!
oh how I hate that
why in the world does he log things to a file and continue the program and not assert(0); or something
 
heh
 
cpx
1:22 PM
@SSight3 do you mean programmers?
 
How ironic. Chrome crashed on me.
@cpx What's the difference?
Well, real coders chew bugs for breakfast and produce WinAPI function calls for lunch.
 
anyone up on threads here!?
 
@JohannesSchaublitb how far up?
 
@jalf About 404 metres high?
 
I remember from a presentation of Hans Boehm ("C++ and Threads" or something) he said that initialization of local statics is thread safe in C++ but that it will not require a lock in implementations
I don't understand how that will work without locks
he said that a new algorithm was found to do threadsafe initialization without locks.
but didn't detail on it
 
1:25 PM
ah yeah, I remember reading the same thing. Not sure how they pull that off
 
cpx
hmm how do you get embeded youtube link?
 
just post the link
this is a magic fairy chat. It just works :)
 
@jalf This is how all code in the future should be like.
@cpx To quote a comment: "this video should be title software engineer vs programmer. As essentially programmer and coder are the same thing.". And to quote myself earlier:
"...Only SO users can get worked up over semantics..."
 
@SSight3 no, that's C++ programmers, not SO users in general ;)
 
1:31 PM
@jalf Sounds like something I should test.
 
ugh, seems so random which instructions are supported
worst instruction set ever
 
he says it in that video
im searching for the point in time currently..
 
it's easy to do threadsafe init without locks
want me to show-u-the-codez?
 
Hello All, quick simple question. When counting the char values in a string, do you start at zero or one?
 
perhaps he was talking about spinlocks?
 
1:41 PM
@DeadMG Sure.
 
principle is simple- create an initialization function, create a static function pointer to it initialized before hand
atomically swap it with null
if the result is non-null, it hasn't yet been initialized, so call
else, it's already been done, so win
 
yeah, I was just thinking of some pointer swappy stuff
 
although it's not quite complete
 
but nice :)
 
because if the init takes some time, you could see it as initialized whilst construction is going on
but I reckon a couple more swaps could fix that problem
 
1:45 PM
yeah, I can see the idea, although an interlocked operation every time you access a static isn't quite ideal either
 
true
but I think that it can be bettered
 
then again, that could probably be avoided. Do a regular read of it, and only if it's null, do the atomic swap
 
loads of word-variables are atomic, so you could just load it and then only go to interlocked
 
since we know that it starts out as null, and is only modified once, setting it to non-null
 
no, it's the otherway around
it starts out as non-null, which is the function that actually does the init
 
1:46 PM
fine, but the principle is the same ;)
 
then it's swapped to null
yeah
the problem is the time the constructor might take
if you don't have a lock, it's going to be hard to make sure it's not seen whilst constructing
 
yeah, but you can always force other threads to wait on a lock during initialization. As long as it can be avoided afterwards
 
yeah
 
the main thing is that post-initialization, you shouldn't have to take any locks
 
I think that it can definitely be improved to achieve that
but I think that the basic principle is solid
 
1:49 PM
yeah
I was thinking of swapping a pointer to the static itself, but a pointer to the init function makes more sense
 
originally, I was going to swap it with an empty function
so that it was guaranteed to be safe when called
but I was thinking that you could swap it with a function that waits on a lock during init
and then swap it with empty function or null
 
I found another solution to the "unpack" tuple for function call problem: stackoverflow.com/questions/7858817/…
 
Starting Monday, I will teach C for two weeks. Number of students: 3
 
lol
 
do you advertise staff:student ratios like that in the prospectus?
 
1:58 PM
It's not a University lecture :)
@awoodland What's a prospectus?
 
@FredOverflow heh, how come?
 
a University advertisement, basically
 
@FredOverflow marketing bumpf that they put shiny pictures of the non-nerdy students in
 
Well, it's not University.
 
what is it then?
 
1:59 PM
@jalf How come what?
 
how come you're teaching 3 students C?
 
It's part of a programming curriculum at an insurance company.
 
ah
 
It's nice to get out of the ivory tower once in a while and get in touch with the real world :)
puts("hello real world!");
 
:)
 
2:02 PM
My schedule for the next two weeks looks like this:
Mon teach C in the real world
Tue teach C in the real world
Wed teach C++ in the ivory tower
Thu teach C in the real world
Fri teach C in the real world
Let's hope I don't get confused :)
 
Are you saying I don't live in the real world?
I'm a real human and I live in the real world!
sometimes
 
when?
 
I walked to a shop the other day!
 
Was it a Photoshop?
 
no
it was a real shop that sold real food
 
2:10 PM
Did your stomach like the food?
 
it's shut up for now
but I ate way too much of it
note to self: include the string header
you know, I think whoever designed Java's syntax is dumb
 
oh my, my test passes
note, that's test, singular. Just the one
 
gz?
 
ty
oh, I'm on a roll now. Both less than and equality works
 
2:28 PM
@jalf ahh i found it
0
Q: Local static initialization without holding a lock avoids a possible deadlock in C++11?

Johannes Schaub - litbIn paper http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2660.htm an algorithm is presented that does not need to hold a lock during the initialization of a local static variable but still causes concurrent flow of control through the variable definition to wait until initialization fini...

 
by the way
my proposed example as for how that algorithm could work is wrong
or maybe I just forgot how it works
:P
 
when it gets to threads im saying goodbye and let the others do
 
heh
 
man, I screwed up my lexer design again
:(
doesn't help that I keep forgetting my grammar :P
 
2:43 PM
you should write it down ;)
 
I did
it's around somewhere :P
 
TODO: GL loader that doesn't suck.
 
what's a GL?
or you mean OpenGL?
 
Yeah.
 

« first day (371 days earlier)      last day (4578 days later) »