« first day (705 days earlier)      last day (4234 days later) » 

6:00 AM
There's the header guard. It's part of the actual header, and protects that header.
 
you know, I had a lot of plans for this weekend. We were to have a football match. Next I was to go over to my friend's house for some multiplayer games. Then head to the Lulu Mall. Maybe study some calculus etc. But now that the weekend has actually arrived, I wonder why suddenly I've fucked everything and am spending the day reading XKCD while eating potato chips.
 
Right now, your own headers do not cause errors since you're only using them in one source file.
 
And the weirdest part is, I think I'm having more fun than if I had carried out my plans.
 
But if you include your headers multiple times in your source files, which can happen indirectly in complex projects, the include guards are there to prevent multiple definition errors.
 
@ApprenticeHacker Wut.
It's Thursday.
 
6:01 AM
The standard headers already have include guards in them. That's why when you include them multiple times in the same source file (directly or indirectly), you don't get errors.
Try this out yourself. Do a #include <string> multiple times and see what happens.
 
@R.MartinhoFernandes it's a weekend
 
Now try doing that with one of your own header files that do not have include guards. (Make sure your header has something in it, like a function).
@ApprenticeHacker It's not everywhere else. Remember the population of chat regulars here span continents.
 
@Insilico This is really confusing
Ill just go by what works
 
@Insilico yeah. Sorry about that. Guess I should have clarified.
 
@ApprenticeHacker Oh. Wow.
 
6:04 AM
@MohamedAhmedNabil Just put include guards on all your header files and you'll be fine.
 
@Insilico ok
 
You can even use #pragma once on Visual C++ compilers, if you wish.
 
@Insilico, I know GCC supports that now.
 
the confusing part is the fact that im not getting any errors at all, I guess ill just use the guards just in case
 
@MohamedAhmedNabil #pragma once is way better.
 
6:06 AM
@MohamedAhmedNabil Yes, you won't always get errors. It depends on how your header files are being included in source files.
 
@MohamedAhmedNabil, How are you using the guards?
 
@chris not using them at all ATM
 
@MohamedAhmedNabil On more complex projects include guards are practically mandatory.
It's good to try to get in the habit of putting them there.
 
@Insilico is a bot considered complex or not?
 
@MohamedAhmedNabil Is it more intelligent than the average Youtube commentator?
 
6:07 AM
@Insilico Alot
 
okay, got to go do some absolutely redundant and useless chores that my mom tortures me with. bye all
 
@MohamedAhmedNabil Then yes. lol.
 
@MohamedAhmedNabil Maybe, or maybe not -- but don't worry about it. Just use the include guards. There's not really a lower-limit on complexity before you use them. Under normal circumstances, it's better to just get in the habit of using them in all headers.
 
When coding should i write my functions first or main first?
 
Rule of thumb: it's a header => needs header guards.
 
6:10 AM
@MohamedAhmedNabil Depends. Sometimes I would write out the skeleton of the functions I think I might use then fill them in whatever order I feel would get the job done fast.
 
@MohamedAhmedNabil main is a function. If you have enough functions in a file that their order matters much, chances are good that's a problem in itself.
 
The only thing your compiler cares about is that you've declared the function before you used it.
Make sure there is some logical structure to your code. It shouldn't be impossible to have an idea what your code is doing.
 
Just one last thing.
What is the difference between source and resource files?
 
resource files are a Windows thing
 
@MohamedAhmedNabil Source files is what you write your C++ code in. Resource files have nothing to do with C++.
 
6:17 AM
At least that's what it's called in Windows. It might be called something else in other OSs.
 
On Windows, it usually refers to files that store things like icons and bitmaps which end up in the .exe file itself during compilation.
 
@Insilico but it wont matter if i put my .cpp files in the resource files folder?
 
@Insilico They're just dumped into the static memory sections right?
 
@MohamedAhmedNabil Your compiler doesn't care where you put your files as long as it can find them.
 
@MohamedAhmedNabil It won't, but why do you want to do that?
 
6:18 AM
Or probably even lower than that - in memory that isn't loaded into memory when the program launches.
 
But putting .cpp files in a folder called Resources will confuse the hell out of anybody who reads your code.
 
@Insilico I didnt know that
@Prætorian because i Didnt know what resource files are
 
@Mysticial I think it's loaded on-demand as it's needed by the Windows memory manager. But the resources do end up embedded in the .exe binary itself.
 
@Mysticial VS does special things with resources, such as map them to addresses in the low 64k address area, which are invalid for regular usage. And I think these addresses are used as handles to fetch the resources on demand somehow
 
oh gawd libpng's setjmp-based error checking mechanism is hurting my eyeballs.
 
6:20 AM
I've written a couple of very small WinAPI GUI apps and I used resources to embed the icon and dialog designs.
 
You can also create and/or modify resources on the fly while the application is running. I haven't seen that used often, though.
You can store pretty much anything as "resources" in a Windows executable.
 
@Prætorian Interesting... so how do self-extractors work? They can have hundreds of MBs or GBs of resource data? Do they get dumped into the end of the binary?
 
Resources are also handy for localization, you can store string tables, and MFC's CString and the ATL counterpart both support fetching these using resource identifiers
 
@Mysticial I don't know if self-extractors store the .exes as resources or just simply concatenate the binaries and making sure the PE header of the main .exe cause the OS to ignore them or something.
 
@Mysticial I have no idea how those work
 
6:25 AM
It might be the same way .net applications work. They look just like executables but have the CLR code as a payload instead of actual processor instructions.
Whether those have a "stub" executable portion that loads the .net runtime or the OS loader itself loads them I have no idea.
 
@Insilico I wanna believe it's the first, but knowing MS and their love for special casing stuff, it could be the second :)
 
@Mysticial Most resources are only loaded when you ask them to be. You have LoadBitmap, LoadCursor, etc. to load the usual kinds of resources. You can also specify custom resource types, and store what you want to there, and load them with LoadResource. So, a self extracting executable will basically have the extractor as the "executable". That'll typically load the resource source, expand it, and execute it (either by loading it into memory and jumping to its entry, or as a separate process).
 
@Insilico Concatenating. A selfextracter looks like selfmodifying code to the OS/virusscan
 
@JerryCoffin How are they usually prepared by the person who makes the self-extracting archives? Is there a "template" self-extractor that a self-extractor-factory uses then "puts in" the target exe?
 
@JerryCoffin That's just compressed resources, which is something else entirely than a self-extracting (packed) executable
 
6:30 AM
@sehe I don't recall mentioning self-modifying code.
 
Come to think of it, when you run a .exe, does Windows load the entire static section into memory from the start? If it does then there'd need to be a separate resource section that Windows knows not to load into memory.
 
Try OllyDbg on an exe prepared with upx-nrv or something
7 mins ago, by In silico
@Mysticial I don't know if self-extractors store the .exes as resources or just simply concatenate the binaries and making sure the PE header of the main .exe cause the OS to ignore them or something.
@Mysticial It memory maps the entire base image, yes. Whether or not it gets paged into physical memory pages depends solely on use
 
@sehe That doesn't require self-modifying code. How is that different from what compilers do when I build my applications?
 
@Insilico I'm just saying what exe packers usually do. I didn't say you said it.
 
@Insilico Neither. A .NET executable always depends on one particular DLL (Don't remember the name). A DLL can (and this does) have an entry point that gets called when the DLL loads or unloads (among other things). In this case, it starts up the VM, which finds the CLR code, and starts executing it.
 
6:32 AM
@JerryCoffin mscorlib
 
@sehe Reread what I said.
@sehe Sounds right.
 
Okay, anybody know how to translate this to C++nese? if (setjmp(png_jmpbuf(png_ptr))) {}
What the hell does setjmp do?
 
@JerryCoffin Erm. But the term resource seems confused there. It doesn't actually need to be a 'legit' resource. It can be any proprietary format chosen by the packer. Agreed for the rest
@Insilico I'd say: exceptions. Not wholly the same semantics (in fact, usually waaaaaay better because of stack unwinding)
To be honest, I suggest reading up on setjmp/longjmp if you need it
 
@Insilico It sets a point of execution that longjmp can go back to. @sehe is right: the usual replacement will be a try, which will be returned to by a throw.
 
@JerryCoffin Hmmm. Apparently libpng requires that I setjmp every time I enter a new routine. -__-
 
6:38 AM
@Insilico Really? I almost can't believe it is mandatory. I think that may preclude it's use from programs that use setjmp for other purposes. Also, there might a more modern / c++ library for that...
 
mawning
 
@Insilico That sounds like a user friendly library :-S
 
> Suppose that you want to use an external library (e.g., libpng or libjpeg) that, in terms of error handling, only gives you a choice between an approach based on setjmp()/longjmp(), or aborting the program
 
@sehe I can disable it, but it causes to abort() the application in case there's an error instead. -__-
 
6:38 AM
Seems legit ^
@TonyTheLion Yeah, I browsed that up when Andrei mentioned it, too :)
 
@Insilico Sounds like time to find a different library (I've heard that LodePng is decent, though I've never tried it).
 
Turned out I knew it, but forgot about it
 
@sehe Why would it interfere with other uses of setjmp? setjmp takes a libpng specific buffer.
 
I had never heard of it
 
@JerryCoffin Yeah, libpng is quite frankly pissing me off. It has no problems writing 10,000 megapixel PNGs though, so whatever replacement library I use needs to be able to deal with that.
 
6:40 AM
Ok. I have never used setjmp so I wasn't sure whether that was possible. In fact, I had somehow remembered that setjmp was 'global' (like, errno).
Hence:
4 mins ago, by sehe
To be honest, I suggest reading up on setjmp/longjmp if you need it
 
(Actually it's ~10,871 megapixels)
@JerryCoffin I'll take a look, thanks.
 
@Insilico Is that a thousands separator you got there, or are you just a happy snapper?
 
@sehe Doesn't help that the period and the comma are right next to each other on the keyboard.
 
@Insilico You know, the edit doesn't clarify one bit :) Are you by any chance American?
 
@Insilico I'll admit, I have no idea about how well most libraries will handle that.
 
6:42 AM
@sehe Okay, it's a 10871635968 pixel PNG. :-) (Yes, the comma is the thousands separator in the U.S. where I live)
(And yes, that XKCD "world" is 10,871,635,968 pixels. That's 10 billion pixels.)
 
@sehe It adds three significant digits, which should clarify by a little over 10 bits.
 
@Insilico Nothing particular, but I guessed as much when you somehow implied that editing into a comma would make it somehow... unambiguous. People in general tend to forget not the whole world has the same locale conventions, but Americans appear to have this syndrom slightly amplified :)
 
@Insilico Are you still messing with this morning's xkcd? :)
 
@Insilico Uh-oh, you used the word "billion" now!
@Prætorian Yesterday morning's xkcd.
 
6:45 AM
@Prætorian Yes, although I've stopped-and-stopped at times throughout the day since I have other crap to do.
 
@Insilico ...or 10 milliard, depending on where you live.
 
@JerryCoffin Yeah, I was pondering a joke like that. However, I couldn't mentally work out that 0x2c (',') and 0x2e ('.') are in fact Grey-neighbours... (having a Hamming distance of 1). I think it does clarify precisely one bit (haven't checked)
 
@JerryCoffin Okay, fine. It's 1.0871635968e10 pixels.
 
Or should I say, 'clearify' rather than clarify
 
6:47 AM
how do i know the x and y values of the point my cursor is pointing to
 
@MohamedAhmedNabil In the console or on a GUI? Or with respect to the desktop?
 
@MohamedAhmedNabil, GetCursorPos is most likely what you want.
 
@Insilico desktop i guess
 
@MohamedAhmedNabil Take a ruler, align to top of screen, read out, align to side, read out. Write the values down, scan paper, OCR, validate and convert to viewport coordinates. You'll need to know the DPI setting for the screen, though
 
@Insilico See, people complain about computers and programmers having incompatibilities, but we're really nearly the only people who come up with anything that's reasonably universal. Example: there are about 15 different standards for voltage, frequency and plug types for something as simple as powering a device. Power over Ethernet is basically the only thing that works the same everywhere.
 
No no, Im making a program that includes moving the cursor to a certain point
Not code, Is there a way to see where my cursor is on the screen. Maybe some sort of program?
 
@MohamedAhmedNabil I recall you asking:
1 min ago, by Mohamed Ahmed Nabil
how do i know the x and y values of the point my cursor is pointing to
 
@MohamedAhmedNabil What cursor? What screen? What OS?
 
@Insilico I meant be somesort of program that would tell me the X an Y of where my cursor is
 
GetCursorPos?
 
6:50 AM
@sehe, Windows
 
@MohamedAhmedNabil What's wrong with calling GetCursorPos in a loop?
 
well, if you are on windows, it is, just one line of code.
 
@MohamedAhmedNabil I kindly request you to take your question to [SO].
Do not forget to specify the requirements
 
@sehe ill take it to superuser
 
(I remember using that in high school to write... let's just say it was not something you'd be happy to run accidentally)
 
6:51 AM
Are you trying to track it or something?
Oh, I see, nevermind.
 
@sehe A friend once told me a story about an old colleague who worked extensively with MS Excel and has a series of equidistant dot marked on his monitor with a sharpie, so he could align his columns perfectly
 
@MohamedAhmedNabil Super User should give you existing tools for the job. Stack Overflow for programming API's
@Prætorian Brillant
 
@sehe I was thinking about existing tools
 
@chris Sooooo. You're either psychic or sock-puppeting?
@MohamedAhmedNabil Ok
 
@sehe, Don't let it out.
 
6:53 AM
Huh? What
@MohamedAhmedNabil Don't forget to google it first though. Seems like it'll work
 
@sehe Or he's making a guess from his previous conversations with Mohammed.
 
@R.MartinhoFernandes That falls under 'psychic' :)
 
@chris I was just stumped by the lack of qualification. If you'd say 'I think he's on windows' - that'd be clear :)
@R.MartinhoFernandes Is it back working yet?
 
I don't remember it being down.
 
6:55 AM
@MohamedAhmedNabil just forget about YT for software :)
 
@sehe, Yeah, I knew he was on Windows from previous questions, so I thought I'd give that one.
 
@R.MartinhoFernandes Didn't work yesterday (submitting the form gave "'/' resource not found" server error)
 
@chris Thanks!
@R.MartinhoFernandes Ermm. Yeah, it looked ASP.Net-ish
 
@R.MartinhoFernandes wtf... who made that?
 
6:57 AM
@R.MartinhoFernandes Still the same for me
 
Works fine here.
 
works_on_my_machine.png
 
Wait, there's no /search.
 
It's what it redirects to on clicking the search button. Browser specific junk, I guess
 
Hmm, sounds like browser sniffing.
 
6:59 AM
Precisely
 
0
Q: Why memory allocation of 2^80 bytes doesn't fail?

Alexander MalakhovFollowing code doesn't throw exception and prints "success". Why ? #include <iostream> int main() { char* data = new char[1024*1024*1024*1024*1024*1024*1024*1024]; if (data == NULL) std::cout << "fail" << std::endl; else std::cout << "succes...

^^ facepalm..............
 
@Mysticial lol
 
@R.MartinhoFernandes Interestingly, Chrome does work, but changing the user-agent in Opera doesn't. Might be cached... Lemme check
 
@MohamedAhmedNabil It's actually a bit non-trivial. To see mouse positions (when it's not over your window) you'll need to set a mouse hook, and display the cursor pos every time the mouse moves.
 
haha... Als completely overlooks that...
 
7:02 AM
@Mysticial Why are people so bad with numbers of extreme orders of magnitude?
 
@Mysticial One thing should not stand without correction there (I'll handle it): new doesn't return null.
 
@Mysticial, I just noticed that.
 
1
A: I am looking for a windows spy application

Jerry CoffinYes -- it's Spy++, which is included in the Microsoft Windows SDK.

 
posted on September 20, 2012 by Anders Schau Knatten

In which I introduce private inheritance, but discourage its use. When inheriting in C++, you normally see It’s almost as if public is synonymous to inherits from. But did you know there is also private inheritance, and why you (probably) don’t see it a lot? When inheriting publicly from a base class, all base members [...]

 
^ Your own answer (@JerryCoffin)
@MohamedAhmedNabil have a look at some of the tools in the answers here stackoverflow.com/a/4038746/85371
 
7:04 AM
@sehe Thank you, I got some answers on super user aswell
 
> Misread..Misjudged...Hangover... - poor Als (10k+)
@MohamedAhmedNabil See, that's what these sites are for :)
 
@sehe Yes, but that's like somebody asking how they can get a quick lunch, and replying with "buy McDonalds corporation".
 
@JerryCoffin Hmmm. I don't think that highly of Spy++ :). But it is the prototypical type of tool that demonstrates what you described. There'll be API Hijack, but it's not trivial to use (and it is more associated with gray-hat scene AFAICT)
 
I have to say, even though my first reaction was a double-facepalm, this question gave me a good laugh. And the fact that it shows research effort means I will upvote it. The title itself is a fine example of click-bait. — Mysticial 40 secs ago
 
@sehe I think about as highly of Spy++ as I do of McDonalds (Hint: in the last 20 years I've eaten at McDonalds fewer than 10 times).
 
7:09 AM
I prefer WinSpy++ aside from no message capturing.
 
@JerryCoffin We should be a team
Lost a few points of sanity with these changesets. http://twitpic.com/awfi1o
 
For the record, compiling with $ g++ -Wall -Wextra -pedantic produces the following output: "q12507456.c++:5:42: warning: integer overflow in expression [-Woverflow]". — R. Martinho Fernandes 26 secs ago
Yet another question that can be answered by the compiler itself.
Actually, I made it a real answer stackoverflow.com/a/12507715/46642
 
#include <windows.h" - Really? The compiler gave that one away...
0
Q: Warning RC4011: identifier truncated to

Iron-EagleI am having trouble compiling RC file. It was absolutely fine in VS 2005 but when I moved to VS 2012 troubles started. That is what I have in RC file: #include <windows.h" #include AGPRODVERPATH That is what I have in .props file: <ResourceCompile> <AdditionalOptions> -DAGPRODVERPATH...

 
Wow, it's kind of amusing to watch your cursor flicker when you put it right on the edge of a tag.
 
7:21 AM
@chris get a steady hand/mouse
 
Hmm, clang doesn't warn on that overflow.
 
@sehe It's not lack of steadiness. It's that the "button" moves (upward) when pressed (i.e., the "shadow" disappears), so if the cursor is right at the bottom border, it presses, which moves the button, which un-presses, which releases the button, which presses...
 
Hmmm... lodepng doesn't have a way to just "stream" the data in and out rather than loading the whole damn thing in memory
 
Wooooo got my C badge \:D/
 
Is there a command in C++ to go back to the begging of the loop or not?
 
7:30 AM
@MohamedAhmedNabil continue
 
@Insilico thanx. Google Isnt helpful when you have a question like this :(
 
@MohamedAhmedNabil Do you have a C++ book?
 
@R.MartinhoFernandes that is fail.
 
@LuchianGrigore Congratulations. Now you can attend the meetings of the super-secret Gold-C badge society. Unfortunately, it's so secret that even members aren't allowed to know where the meetings are held...
 
@Insilico Yes, I havent finished it. I have done 9 chapters out of 18 so far. Im writing this program solo
 
7:31 AM
@JerryCoffin lol
 
@MohamedAhmedNabil It should've covered the use of continue somewhere.
 
@JerryCoffin did your invite get lost in the mail? :(
 
@Insilico Maybe later on in the book, It did cover break thou
 
Should be right beside break.
 
Would saying that C is annoying rather than hard be a fair argument?
 
7:34 AM
@LuchianGrigore No, they told me where to go. In fact, people constantly tell me where to go. Loudly!
@TonyTheLion Not exactly. C is simple, but using it well is exceptionally difficult.
 
ah right
 
morning all
 
@LuchianGrigore Damn, I'm looking at your recent badges list and your Great Answer badge isn't on the recent 10... Did that matrix question really give you that many badges?
 
@Mysticial it did, at least 5...
 
It seems like the simple of act of linking to your question gave you:
Good Question
Popular Question
Notable Question
Favorite Question
performance
Good Answer
 
7:38 AM
@TonyTheLion It's like a pocket knife. There are old geezers who can pull out a knife and whittle almost anything imaginable out of a piece of wood -- but for most people, it's a quick route to a cut finger. Either way, however, the knife itself is almost trivially simple. Piece of steel, sharp on one side, handle on one end.
 
@Mysticial get you a beer sometime
 
@Rapptz, Wow, never seen that one.
brb looping it
 
@JerryCoffin heh. Good analogy there.
 
7:40 AM
@LuchianGrigore I was just mentioning that haha
 
Where in the standard does it say that if initialization of a member fails, all previously constructed members are cleaned up nicely?
 
@Rapptz To read monetary values. Especially useful when you want the currency specified, but don't want to manually check against all the strings that can stand for various currencies.
 
Ah, I think I found it. But it seems to be one of those roundabout implied things :( Not good for quoting.
 
@LuchianGrigore Yeah, it's kinda funny sometimes to see random people get caught in the crossfire of some of my answers. - Nah, I don't really drink anymore. Had a bad experience a few years back.
 
7:46 AM
@R.MartinhoFernandes §15.2/2 (in C++03, same section, slightly different wording in C++11): "An object that is partially constructed or partially destroyed will have destructors executed for all of its fully constructed subobjects, that is, for subobjects for which the constructor has completed execution and the destructor has not yet begun execution."
 
@JerryCoffin Oh thanks. It's even the same reference.
 
@Mysticial: I've done about 2^80 facepalms since I've read your 1st comment and also had a good laugh. I guess, the fact that it's my 14th day as C++ developer can give me a bit of excuse, though. — Alexander Malakhov 1 min ago
 
1,208,925,819,614,629,174,706,176 facepalms?
 
@Rapptz Probably smashed his skull by now.
 
@R.MartinhoFernandes at the very least he would be left with a bloody stump of an arm
 
7:51 AM
The question is: how much energy would be required to perform that many facepalms?
 
@R.MartinhoFernandes How much does an arm weigh, on average?
 
Morning gents and robot
 
@R.MartinhoFernandes that's a simple question, once you know how much energy per face palm, and that is a more pressing question as far as I am concerned
 
So let's assume that an arm is about 10 pounds, or about 4.54 kilograms.
 
@thecoshman I have a feeling the total is more than the energy available in the observable universe.
@Insilico To be honest, I wouldn't know.
 
7:53 AM
can anyone tell me whats wrong with my leftclick function ? ideone.com/8yxQy
 
I don't think I ever lifted an arm that wasn't mine, and that makes it a bit hard to evaluate weight :)
 
Also assume that the arm is a rod, of uniform density (which is probably a crappy assumption but whatever)
We can probably use the moment of inertia and figure out a ballpark estimate.
 
@R.MartinhoFernandes Depends on the speed. To have done it already, infinite, because he'd have had to accelerate his arm to well above the speed of light.
 
And it's on the multicollider...
 
It'll be on reddit tomorrow.
 
7:57 AM
rotational kinetic energy = 1/2 * moment of inertia * angular velocity ^ 2
 
It'll amass about ~1200 upvotes and it'll be on the multicollider for a few days.
 
Figure out what the angular velocity of a facepalm is, plug it in and multiply by 2 ^ 80.
 
A typical facepalm covers what? 20-30 degrees?
 
I'd say 45
 
@R.MartinhoFernandes That would be angular displacement. How fast does it happen, though?
 
7:58 AM
I wager it takes something on the order of 400 miliseconds.
 
Okay, 1/2 second then. 1/2 second to cover 45 degrees. That's 90 degrees/second
Which is pi/2 radians / second
 
@Mysticial Does that mean I'll get badgers?
 
I counted 21 facepalms in 10 seconds.
 
@R.MartinhoFernandes at first I was shocked by such a foolish claim, but then I remembered just how many facepalms we are talking about here. Though, you also need to consider that the energy is not being used in one go
 
How long is a human arm, on average?
 
7:59 AM
@Insilico One cubit.
@thecoshman Erm, it's not reusable.
 
@Insilico One yard from nose to finger tips. Forearm is roughly two thirds of that.
 
Actually I should be looking at the forearm, not the entire arm.
 

« first day (705 days earlier)      last day (4234 days later) »