« first day (169 days earlier)      last day (4772 days later) » 

cpx
1:31 AM
Is there a use of inheritance in software apart from deriving game characters?
 
Xeo
everytime there is a "is-a"-relationship
a button is a widget
a circle is a shape
and so on
 
 
2 hours later…
3:32 AM
hello
 
3:43 AM
aaahaha c++0x silver badge just arrived!
 
Xeo
you're the first one
and you said you don't know much about c++0x ?
 
 
1 hour later…
user379888
4:54 AM
Please tell me which image bin do you all use?
 
user379888
@tina:Everyone. Includes you :)
 
user379888
5:45 AM
Why do we need to define a class variable?
 
6:10 AM
@user388338 - Thanks
 
 
5 hours later…
Xeo
11:08 AM
I'm somehow reluctant to answer 'There is nothing we can do's questions... am I the only one?
3
 
hi everyone :)
 
11:39 AM
@Xeo you're definitely not the only one
he's a pain in the ****
 
Xeo
it also seems he doesn't like to accept answers, that don't provide a solution to do sth exactly the way he wanted to
 
@Xeo I wouldn't bother with him anymore
@sbi and others have also tried to get some sense out of him and only got frustrated
 
12:24 PM
@Xeo 316 questions vs. 15 answers? Wow. Just wow.
 
@Xeo no, but the questions have improved in quality over last half year or so
 
@AlfPSteinbach, @tina has been worried that you haven't been here for the last day or so... LOL :P
 
ok, thx
@johannes congratz how do that without them s.p.'s?
 
ti-na loves a-alf, ti-na loves a-alf... :)
 
@FredOverflow i think we should be kind to all people, fred
 
12:36 PM
How is love not a kind thing? I'm just jealous of you two :(
Wish I had my own private C++ tutoring room...
 
12:52 PM
Hi folks. It's too beautiful weather to stay in there I would say.. but I still need to get some work done..
trying to find a simple formula for specular reflection
http://codepad.org/AqWxuyIF
IMHO the output should be [3, -2, 0] ..?
Could anybody look at my code?
meow
^ @PiotrLegnica
 
What's makeVec for, and why is dotP a macro? Also, the easiest way is to just trace it with the debugger.
 
yeah you wouldn't need makeVec
why should dotP not be a macro?
 
Don't use macros unless you really need to.
 
@AlfPSteinbach just providing lots of answers (i'm at 80 currently. I was told yesterday that you need at leaswt 80 answers in addition to at least 400 upvotes to get the silver badge). So while @JamesMcNellis is soon at 400 upvotes too, he still needs 20 answers to get the badge xD
 
I know, so an inline function would also be good
 
1:05 PM
@JohannesSchaublitb thx info. happy i'm not competing. he he. would be stressful i think. but good that some do
 
@PiotrLegnica It's more the formula I'm not sure about..
 
 
3 hours later…
Xeo
4:08 PM
1
Q: Variadic macro argument count macro fails in VS2010 but works on Ideone?

XeoI got the following implementation to get the number of arguments in a variadic macro (currently limited to 16 args). However, for VS2010 the output is always 1, no matter how many arguments are passed. On Ideone.com, the output is correct, bringing me to the conclusion that I must have missed so...

throws his question in, hoping for an explanation
 
 
2 hours later…
6:21 PM
@JohannesSchaublitb Each of the 80 answers has to have at least one upvote too, so I can't just spam the tag (not that I would).
There are some tags where there is just no competition, e.g., stackoverflow.com/tags/templates/topusers :-D
 
6:37 PM
6 hours ago, by FredOverflow
ti-na loves a-alf, ti-na loves a-alf... :)
lol
 
ti-na and a-alf sitting in a tree
H-A-S-H-I-N-G
 
Xeo
yet another random windows function: win-key + arrow keys
 
sbi
7:30 PM
@Xeo He's not worth the trouble.
 
7:53 PM
hi
how does C++ implement member reference data?
 
sbi
@wilhelmtell ??
 
@wilhelmtell Probably as pointers
 
@FredOverflow so dereferencing a member reference data is more expensive than a none-member reference?
 
I have no idea. Why don't you just look at the generated assembly?
 
because that says nothing about C++
@sbi ??
 
7:57 PM
@wilhelmt -- member reference data -- you mean like "byte packing"? Or, through access through pointer-to-member?
 
@charley struct s { T& mem; };
 
Xeo
doesn't matter if member reference or normal reference, no?
 
@Xeo none-member reference can have zero overhead in dereference because they're allowed to be anywhere in memory.
 
Well ... it would matter if you want to "reference this member in that object" (you need a reference-to-member, which MAY perform indirection through a virtual table, when you have multiple inheritence). Otherwise, if you ACTUALLY had a reference to an "int" in memory, and that "int" accidentally happened to be a member of an object, yes, that too would work (but generally frowned upon).
 
@charley i'm not following you.
@charley what do vtables have to do with this?
 
8:03 PM
Sorry -- I just saw what you posted: struct s { T& mem; }; will have one member, sizeof(T&), which is probably four bytes (assuming four bytes for an address, since the member is actually a poitner). However, depending on the compiler settings, the object may be "byte packed" or "adjusted" to byte-align, so the structure may have more than four bytes. In that case, the address of the "mem" member may not start at offset zero. (Or, are you talking about how to initialize an instance?)
 
@charley so you're saying it's going to be a pointer? in the example chances are there won't be any alignment if it's going to be a pointer, because a pointer is word-sized. i don't see in the standard any mention of the memory layout of a struct with a reference or of the cost of dererferencing a member reference.
i should probably say "accessing" a reference. but there are no language lawyers here, i presume, so i'm safe.
 
Yes, references are always (internally) implemented as pointers. They are effectively pointers that can't be "NULL", although you can force them NULL if you want: int& i = ((int)0); So, references can always be viewed as "mere syntactic sugar for pointers".
In theory, the cost of dereferencing is pretty much zero: It should be the same as the cost of accessing a pointer (which is one of the fastest things a program can perform).
...I meant "accessing through a pointer".
 
@Xeo Wow, that is actually pretty slick! I wonder how well it works with multiple monitors... the "drag a window to the side to make it autosize to half the screen" doesn't work particularly well with multiple monitors or with remote desktop.
 
@charley "references are always (internally) implemented as pointers" : that's wrong.
 
8:18 PM
more to the point
pointers are explicit references.
 
If you have int i = 42; int& ir = i; in a function, the compiler isn't going to implement ir as a pointer, it's going to eliminate ir entirely.
 
Xeo
@JamesMcNellis dont have a second monitor here for testing :(
 
sbi
@wilhelmtell What do you mean "references as member data"? References in general usually are addresses under the hood (like pointers). Why would there be some special rule for them being member data?
 
I know references are not pointers. I know they are cheaper than pointers and I know dereferencing a pointer is not a zero-cost action. But I'm asking about the specific case of a reference member. Is it different from its none-member counterpart (I presume it is) and if so how?
@sbi compilers are allowed to implement references as aliases for what I know.
 
@wilhelmtell How do you know they are cheaper than pointers? How are you measuring "cheap"?
 
8:22 PM
@GMan wording again, sorry about that. They can be cheaper.
 
Xeo
okay, since litb deleted his answer.. what exactly does the tilde ~ mean in a c/c++ macro?
 
@Xeo AFAIK, ~ has no special meaning in the preprocessor.
 
Nothing.
 
I didn't mean to go into a discussion about references in general. Unless of course I'm completely ignorant of what they are. Which I used to think I'm not.
 
I'm guessing we're in the "standard-is-silent-on-this-topic" thing. For example, I know the HP compiler adds the "return-value" to the prototype of the function, so it is populated directly (and not actually returned-by-value). That's left to the vendor (the standard is silent on such things).
 
8:23 PM
Or rather, bitwise negation, just like outside of it.
 
sbi
@JamesMcNellis @Xeo That's called AeroSnap and is near the top of most feature lists telling you why you should upgrade to Win7. And it works pretty well with multiple monitors. Your window first snaps to the border to the next monitor, then to the next monitor's border to the previous one. Maximizing any window currently on the left monitor to the right monitor is Win + (Right, Right, Up). Pretty snappy, if you ask me. :)
 
@wilhelmtell Can you paraphrase your question about references again, for me?
 
Xeo
@sbi I knew the AeroSnap, but just not the shortcuts for it. :)
 
sbi
@wilhelmtell And what would that mean? Is there any concept for any underlying machine where "alias" is not an address?? And I have never heard the sentiment that references are cheaper than pointers.
 
@GMan struct s { T& mem; };
 
8:25 PM
@sbi Via dragging, I've only ever been able to get windows to snap to the leftmost or rightmost edge, never to an inner edge on my multi-monitor display.
 
sbi
@Xeo Ah. Silly me. I thought that's what AeroSnap was all about... :)
 
Xeo
@sbi Well, you can always drag them, no? ;)
 
@GMan 1: what does C++ say about the memory layout, and 2: what does C++ say about the cost of dereferencing mem?
 
sbi
@JamesMcNellis Definitely works with the keys. I know that because it takes to Right to move a window to the right monitor.
 
@wilhelmtell, in most cases references (unless they can be elided by the compiler) are implemented in terms of pointers, take the same space and will incur the same cost of dereferencing, but the semantics are different
The standard does not say anything about the memory layout, nor does it deal with the cost of dereferencing them, as it does not do so for pointers
 
Xeo
8:27 PM
@JamesMcNellis would be pretty inconvenient if they'd always snap to the inner edge on multiple monitors
 
@sbi I am excited now to go to work tomorrow to find out!
 
@wilhelmtell Reference implementation is unspecified (ergo so is its layout).
 
sbi
@JamesMcNellis TGIM! :)
 
@DavidRodríguezdribeas that's what I thought. That it's a matter of semantics and taking advantage of how the compiler treats references in contrast to pointers.
 
@wilhelmtell, consider that if a reference is stored in an object, the object that is referenced must be accessible through whatever the compiler uses to store as a reference --usually a pointer
 
8:29 PM
@GMan @DavidRodríguezdribeas but structs still must be packed in memory, supposedly, so the reference must have some trace inside the struct to access its data.
 
sbi
@JamesMcNellis And what sweat shop do you work for that you can't afford a second monitor for home? :)
 
@wilhelmtell Yes, of course. But that's all you know: it's there, and its format is unspecified.
 
@wilhelmtell Usually a pointer, as I mentioned before. But you should never really care on the cost of pointers or references. Aim to lower the cost of algorithms, not micro details
 
@GMan but there's an important point here. i shouldn't prefer a member reference over a member pointer "for performance".
 
They aren't interchangeable, so that question is meaningless.
 
8:31 PM
it's something i was just doing, and then it occured to me that i'm a) stupid b) playing with fire c) white.
 
Xeo
I consider references just as convenience, can always use a pointer
 
@sbi Ha! I have three LCDs at home, but I haven't used that PC since I moved; I like using my lappy because it's faster and because I can write code while sitting on the couch :-)
 
Leave the micro-optimisations to the compiler.
 
@wilhelmtell you should NOT even be considering the micro-difference there, as a matter of fact, I think it should be the other way around: if a reference suffices, that is what you should default to
 
@David +1
 
sbi
8:34 PM
@JamesMcNellis Yeah, my desktops is mainly used by the kids for playing games. I sometimes put my 2nd monitor on the living rooms table and hook the laptop to it. Usually when I work at home.
@DavidRodríguezdribeas Rodríguez' razor: Never ascribe to pointers, what could sufficiently be expressed using references.
2
 
Xeo
@sbi reason being because its just so much easier to fuck up with pointers?
 
Use a pointer when you want to point, use a reference when you want to alias.
 
@GMan but you can't alias in a struct. :p
 
IMHO, references are always preferable because you need never check for NULL.
 
@Xeo You cannot emulate const Foo& with pointers at call-site.
 
8:41 PM
@wilhelmtell Wat.
@charley inb4 "but my function's contract says no null pointers"
 
(At our shop, we use pointers only because something might be NULL.)
 
@GMan sorry i mean yes compile-time alias
 
@GMan Pointing is impolite.
 
pointers can get messy easily if you don't watch it
I didn't even know there was a cost to dereferencing, what cost is that exactly?
going to get the data from memory?
 
@Tony Yes. The cost varies, depending on where the data is located (dereferencing a pointer to data in L1 cache is cheap; dereferencing a pointer to data that's been paged to disk is not so cheap).
 
8:46 PM
@JamesMcNellis yea I see, interesting :P
 
Accessing non-local memory on NUMA, very not cheap
 
@JamesMcNellis That is not really the cost of pointing or referencing but rather the cost of reading a variable. In the case of pointers/references, the extra cost (compared to using the actual variable) is that there is a level of indirection. Then again, it is a cost that in general you cannot remove and it is very small in most cases.
The fact is that the time we have been discussing this issue here is much higher than the cost that the dereference will take in most programs.
 
Agree w/DavidRodriguez. At its best, accessing a value means "directly" accessing an address in memory with that value. Dereferencing places an extra step: Access the address-of-the-value in memory, and then access the value implied by that address (which was just accessed). If indirection happens, it is at least two register loads-to-the-value, while directly accessing the value may be one-register-load. (Yes, I concede references in code may be ellided out by the compiler optimization.)
 
does anybody know what makes CUDA texture memory so much faster then it's global memory?
is it comparable to the difference between CPU cache and RAM? for example
 
sbi
9:06 PM
@Xeo Yep. A pointer is a much more powerful tool than a reference. And with that increased power comes increased responsibility, and an increased level of fucked-up-ness when you fail. You wouldn't get the 650W electrical drill/drive machine from the workshop to froth a mug of milk, because if you fail, besides a new mug you will need to renovate the kitchen.
4
 
Mat
@Tony Its optimized for 2D access, some info in this article at DrDobbs.
 
@Mat Thx for the info!!
@sbi Nice way of putting it!! :)
 
@DavidRodríguezdribeas Ok, right: that would be more correct: a pointer introduces an additional memory access. Good clarification.
@sbi Suddenly my espresso machine looks very underpowered.
 
@JamesMcNellis Have you watch an expresso coffee machine explode ever? I watched a very small once and it made quite a mess... the pressure built up and suddenly the coffee holder gave out and grounded coffee was spread all over the kitchen...
 
@DavidRodríguezdribeas Thankfully, no :-D. That sounds exciting, though.
 
9:19 PM
Watched from a distance... I am quite more respectful of those beasts after that
 
Mat
@DavidRodríguezdribeas typical buffer overflow scenario really
 
sbi
9:39 PM
@JamesMcNellis You know, a friend of mine had one of those manual espresso "machines" (whatever they are called), as they have probably used them in Italy for centuries.
Once she had an overnight guest, and he prepared espresso in the morning, and failed to put the metallic sieve/filter in, which she had removed the day before to clean the thing, and which has the job of preventing the coffee powder from being carried by the steam all the way to the top. Therefore the powder did go all the way, and clogged the exit where the steam emerges and condenses to what many of us love to drink in the morning.
So the thing was sitting on her gas stove, the flames turning water into steam, the steam trying to expand, and there's only two ways for it to do that - throu
I'd like to borrow her guardian angel once in a while.
 
9:54 PM
@sbi Wow. I did not realize that I was taking such a risk by making coffee!
 

« first day (169 days earlier)      last day (4772 days later) »