« first day (113 days earlier)      last day (4836 days later) » 

1:00 PM
@Nils Why do you want to replace it? The compiler does a perfectly good job of it.
 
@DeadMG No, it's a character constant... but what it means is implementation defined.
 
Just want to ensure I fully understand it, then I'll use std::array
 
@Nils By the way, it would really help the discussion if you posted the declaration of a :)
 
int n = 10000;
char (*a)[n] = malloc((sizeof *a) * n);
 
@Nils You just have to understand that std::array is not C.
 
1:01 PM
Well of course I do..
So now assert(a[20][10] == *(a + 20*n + 10)); obviously doesn't work, because the second dereference is missing..
 
@Nils Impossible, char (*a)[n] does not compile if n is a variable. Please post the real code.
 
you haven't done anything meaningful with n
 
Also, in C++ you would use std::vector<std::string> instead of this char pointer mess.
 
@David Ok just for the record, this refactoring, inspired by your comment, works like a charm and is actually kind of readable. The only thing I don’t like about it is the presence of break instead of having one loop condition. But I think I can live with that.
 
@Nils There is no second dereference in a 2D array, only in an array of pointers.
 
1:04 PM
ah yeah it does not compile with g++, but seems to be valid C code
 
@FredOverflow Yes it does; Nils is writing C, not C++, isn't he?
 
@CharlesBailey So C has a type char (*)[n] where n is not known at compile-time?
 
@FredOverflow Sry I was referring to a nested array as 2d array. But I don't think C++ has a 2d array type like, C#?
 
@FredOverflow C has VLAs, so yes.
 
@Nils Nested arrays and 2D arrays are synonyms, at least in my world.
 
1:06 PM
ok
 
@FredOverflow Yeah, the standard uses the term multidimensional array for that.
 
@Fred In some languages they are distinct as far as the type system is concerned!
e.g. C#: int[,] vs. int[][]
 
@KonradRudolph Isn't int[][] more or less the C# "equivalent" to int** in C++?
 
so the question was how to replace *(*(a +20) + 10) with a multiplication, given n is the size of the square array a.
 
@FredOverflow TBH, I'm not sure about the language rules, I think that at compile time, it's just an incomplete type.
 
1:08 PM
@Fred yup. Just wanted to draw attention to the fact that nested == multidimensional isn’t always given
 
I guess it would be something like *(a +i*n +j), but I have to dereference it a second time, which I don't understand how to do it.
 
@Nils The effective address would be a + 20*n + 10.
If you really want to write that in code, you would have to say *(&a[0][0] + i*n + j).
Or, alternatively but perhaps more confusing, *(a[0] + i*n + j).
Or you could just say a[i][j] and let the compiler to the dirty job :)
@Nils BTW this is untested code, please let me know if that works.
Great, another audience stunned into silence by multidimensional array-to-pointer decay. Thank you, Dennis Ritchie! :)
 
@FredOverflow assert(a[20][10] == *(a[0] +20*n + 10)); works
 
@Nils: That's a terrible test anyway
if your arithmetic is off, you invoke UB and the test could still pass
 
You could also say (a[0] + 20*n)[10].
 
1:14 PM
it would be better to do assert(&a[20][10] == a[0] + 20*n + 10));
because you want to know that they point to the same object
 
@DeadMG Definitely.
 
yep, thx @FredOverflow
 
But again, if what you want to express is an unknown number of strings of variable size, just use std::vector<std::string>. Readers of your code will be forever grateful.
(Assuming this is a C++ project and not a C project, of course.)
Then you can get rid of all the dirty malloc, free and array-to-pointer decay.
 
sure
Is there any reference on the web which explains how SRAM works.. Wikipedia says "Bistable latch with 4 transistors", but it doesn't really help me understand it is it illustrated somewhere how the current flows? Heh another off topic question, but I guess I rather ask here, then let's say in the C# channel :D
 
it's a recursive NAND something
I did it in physics a couple years ago
 
1:20 PM
so my problem seems to be that my initial vector<vector<char>> is filled with ZERO's and it prints these to the screen as space's, how do I fill it with something that won't be taken as a char to print?
 
I just told you to get high level with std::vector<std::string>, and now you start talking about transistors? ;)
 
basically, when you push 1 through the top input, then it forms a recursive loop which keeps the output as 1
 
@Tony A default-constructed vector has no elements, not even zeros. Show us code.
 
when you push 1 through the bottom input, it breaks the flow and causes the output to go as 0
 
Also, zeros aren't printed as spaces, but as "nothings" (the cursor does not move at all).
 
1:22 PM
@DeadMG thx makes more sense then "bistable latch"
 
At least on my system.
@Nils Are you studying for an exam or something? :)
In that case, arrays and pointers are extremely important.
 
Then forget everything I just told you about strings and vectors. T a[n]; is the way to go.
 
@FredOverflow codepad.org/ILfXvVSB
 
@Tony Aha, you are not default-initializing, the initializer list says _lines(_rows, std::vector<char> (_columns) ).
So yes, you'll get all zeros. I'm sorry, what was it you wanted instead?
 
1:25 PM
@FredOverflow I realized that just now too
something that won't print to the screen
when I output my array to the screen, only what i put in should print and the rest not
 
What does the following code print to your screen?
std::cout << 'a' << char(0) << 'b' << std::endl;
Is there something between the a and the b?
 
@Tony Uhm strangely, for such a short description of the requirements, I still need to ask: What does it mean that only what you put in should print? Does this mean that it should not be visible (as in a space) or that it should not even take space in the screen?
 
@FredOverflow it prints aSPACEb
@DavidRodríguezdribeas it should not take space on the screen
which it is doing now, so messing up my picture
 
My take is that the simplest thing is just adding an if to the inner loop.
 
Well then just replace std::cout << *second_iter; with if (*second_iter) std::cout << *second_iter;...? How hard is that?
But I doubt that would be useful. It should make a visible difference if something is in the first or last slot, right?
@Nils Zürich? Also ist Deutsch Deine Muttersprache? Hehe, noch ein Deutscher im C++ Chat :)
 
1:32 PM
Ja also ich bin Schweizer :)
 
Ok, die Schweiz ist nicht Deutschland, aber wir sprechen dieselbe Sprache... naja fast :)
Wie heißen Pfannkuchen bei Euch? :)
 
@FredOverflow why is it FatherLand but MotherTongue? why not MotherLand and FatherTongue?
 
@AlfPSteinbach Because father does nasty things with his tongue!
 
heh omaelette
Kommt auf den Dialekt an
 
Ist "Raiberdatschi" (keine Ahnung, wie man das schreibt) schweizerisch? :)
Die heißen bei uns "Kartoffelpuffer" :)
Note that C++ is mostly offtopic in this chat. @sbi will be relieved that we finally started talking about something interesting. Food :)
 
1:36 PM
noch nie gehoert
 
ich weiss nicht was "Raiberdatschi" ist? Wie sagt man das auf Englisch?
 
@Tony according to automatic translation: "potato pancake"
 
@FredOverflow never heard of 'em
sounds interesting though
 
ach so
verstehe nun
 
1:39 PM
@Nils Oh, der Begriff kommt aus Bayern :)
 
Heh ok, ich krieg gleich Hunger :D
 
@Tony: So, does the if in the inner loop does what you want?
@Nils Ich auch :) Nachher gibt's bei mir Pellkartoffeln mit Kräuterquark. Allerdings pelle ich die nicht, dazu bin ich zu faul :)
 
hmm hoping that the fridge is non-empty here..
have to go back studying, bye
 
@FredOverflow It does, now I just need to find a way to add the carriage return into my char array, because \r does nothiing
 
1:55 PM
Why would you want to add the carriage return into the data? Simply add std::cout << '\n'; as the last statement of the first loop.
for (; first_iter != _lines.end(); ++first_iter)
{
    std::vector<char>::iterator second_iter = first_iter->begin();
    for (; second_iter != first_iter->end(); ++second_iter)
    {
        if (*second_iter)
        {
            std::cout << *second_iter;
        }
    }
    std::cout << '\n';
}
Also, why aren't you declaring the iterator variable as the first part of the for loop?
for (std::vector<char>::iterator second_iter = first_iter->begin();
     second_iter != first_iter->end(); ++second_iter)
@Tony: This is idiomatic C++.
 
@FredOverflow idiomatic C++? you mean adding the iterator in the for loop?
 
Yes, because then it has exactly the scope it needs.
Also, I just added the @Tony part to make you read the code about std::cout << '\n'; ;)
 
ok thx
:)
 
2:30 PM
@FredOverflow Call me lazy if you will, but I think I'd use something more like:
 
Cliffhanger!
By the way, I finally found a proof for Fermat's theorem that fits on a single line:
 
for (; first_iter != _lines.end(); ++first_iter)
std::cout << std::string(first_iter->begin(); first_iter->end()) << "\n";
Sorry 'bout that.
...but only if I couldn't (after seeing the real code) find a decent way to use std::copy instead.
 
I wouldn't use vector<vector<char> > as the internal representation type in the first place.
std::copy(first_iter->begin(), first_iter->end(), std::ostream_iterator<char>(std::cout, ""));
std::endl(std::cout);
 
@KamilTomšík C++ programmers are not exactly the greatest advocates of design patterns, you know... maybe you'll have more success in the Java chat? ;)
 
Java sucks :-D
 
@FredOverflow You can meaningfully use command pattern for the edit form's undo functionality. But not for representing the edit form iself. It's unclear what you're doing.
 
@KamilTomšík But generally speaking, Java programmers are in love with patterns.
 
why doesn't my reply link to comment i replied to?
 
3:07 PM
Which one?
 
now it got wrong link argh and cannot edit more double argh
 
command pattern should represent future (or already happened) action call, so I guess it is meaningful - action call can have params... I don't see the reason why it couldn't be mutable - that's why I'm asking...
 
@AlfPSteinbach You just invented a new signature for main: int main(int argc, char** argv, double argh)
 
@FredOverflow: Javists overuse patterns
 
@KamilTomšík Yes.
 
3:10 PM
@FredOverflow: Of course that yes, I was one of them :-)
 
@KamilTomšík Glad to hear you're cured :)
Patternitis is hard to overcome...
 
Patternitis is highly contagious, and you need some strong anti-idiotics to cure it.
 
well patterns in general are useful - it is just not good to overuse them - I like idea of factory methods and converters on objects in smalltalk while I don't like the singleton pattern at all
 
I'm sorry, I had all my recollections of the Singleton pattern removed in expensive brain surgery, so I cannot comment on that. Must have had a good reason for that, though...
 
3:48 PM
@FredO: Lucky you
 
@DeadMG Expensive, but totally worth it!
 
lol
 
Now when I hear the term "Singleton", the following comes to mind:
 
@FredOverflow Too many Singletons will leave you with a massive throbbing headache.
 
@CharlesBailey Of course, that's why we drink responsibly, right?
 
4:06 PM
I don't drink at all
but that' just me
 
I drink seldomly. But when I do... I do! :)
 
@FredOverflow I was just talking about code design ;) .
 
@CharlesBailey s/drink/code/ then :)
 
I think perhaps @CharlesBailey only drinks Baileys...
 
@AlfPSteinbach LOL
I think we should invent our own drink and call it "The Stack Overflow". I'd be happy to do beta testing by overflowing my own stack again and again...
It should definitely contain Whisk(e)y. I don't like most other hard liquors.
 
4:15 PM
Norwegians, aquavit. Russians, vodka. Germans, beer. French, vine, cognac. Scotch, scotch. English: tea.
 
Funny, if you translate "whisky" and "aquavit", they mean the same: "water of life" :-)
(Although "water of diziness" or "water of death" might be more appropriate...)
 
yes, but according to Wikipedia aquavit is just the scandinavian form of German schnapps
i think it's like, in Norway and Germany we make hard liquor from potatoes, and beer from malt, while in Scotland they make hard liquor from malt, and beer from potatoes?
 
dizziness and eventual death are normal parts of life.
2
 
(I'm thinking haaard about which nationality to offend next)
 
4:28 PM
@Alf Why restrict yourself to one at a time?
 
heh
 
0
Q: Why are there separate L1 caches for data and instructions?

NilsJust went over some slides and noticed that the L1 cache (at least on Intel CPUs) distinguishes between data and instruction cache, but I also would like to know why this is..

 
 
1 hour later…
5:43 PM
Hey
 
5:59 PM
@Raynos up late?
 
@AlfPSteinbach its 6pm here
I was wondering whether emulating map & reduce on sets in C++ is considered a horrible idea.
 
@Raynos what does that mean?
 
map takes an array and maps all it values to different values returning a new array
Well it takes an array and some kind of function pointer I guess
 
function object
and, more importantly, I just don't see the benefit
a simple iterator-based for loop will easily do what you need
 
Because im trying to write a set manipulation library in C++ and abstraction away the low level data storage of your set so you dont have access to the actaul data to iterate over.
Again this may be an issue of doing something in C++ when clearly its a bad idea.
 
6:13 PM
yeah, but
what actual benefit does it have over the existing iterator system?
 
Not sure. I may be better to give public access to the data so it can be passed into an iterator
 
that's not really what I had in mind
but more like
why would anyone use it?
 
Dont know. Just feature creeping for the heck of it I think.
is cplusplus.com a good or bad website?
 
I have heard many times that it is terrible
however, I have little experience with it personally
 
Ok thats good to hear
Its really poor that most websites that get the highest hits in the search engines are really bad resources for developers
 
6:26 PM
C++ is an extremely complex language
especially one with such a long history evolving from another language
it's statistically likely that the majority of resources on it are terrible
 
I like it, it's very well organized. However, many people say that it is inaccurate. It's been pretty good for me though.
 
another completely different language
I personally use MSDN as my C++ reference
 
@DeadMG don't you feel like relying on microsoft is dangerous there?
 
no, why?
Microsoft have huge legacy C and C++ code-bases and especially in recent years they've put in huge efforts to be Standard conformant with good documentation
if they have a Microsoft-only extension, it's clearly marked, and MSVC isn't notably less conformant than GCC if you have a recent version
 
sbi
6:44 PM
@PrasoonSaurav I wonder what the SO mods will do in a few months, when we've run out of IP addresses, and providers start put us all behind NATs. I'm with the biggest German Internet provider, and might then share my IP externally visible address with thousands of German SO users.
Oh the (coding) horror!
@DavidRodríguezdribeas Urgh. I suppose asking a few innocent questions ("Do you know how to do partially specialize this function template?") won't help in such a case, because those people tend to be convinced that everything they don't know isn't worth knowing anyway.
One thing I have done in a company I worked for is to turn runtime errors (might happen at a customer's) into compile-time errors (won't leave the developer's desk). Sure, it made a few developers angry (what with not enough screen estate to even see those compiler errors all in one piece), but the boss was very convinced when the R&D lead explained to him that it prevents errors in the field. :)
However, if your boss is the culprit...
In general, I found it best to have management that understands technical issues on a above-surface level, knowing enough to know that they mustn't meddle with whatever the developers do under the surface.
I've always worked for rather small companies (the biggest had little over 100 employees, a third of which were developers), where the CEO knows you by first name. I've had two of those who used to code for money in an earlier life (one of them in the very company he lead), but both of them admitted that they never were rock star coders and left the details to those in the know.
 
@Raynos How about this? :)
template <typename T, typename Fun>
auto map(const std::vector<T>& source, Fun fun)
-> std::vector<decltype(fun(T()))>
{
    std::vector<decltype(Fun()(T()))> result;
    for (auto it = source.begin(); it != source.end(); ++it)
        result.push_back(fun(*it));
    return result;
}
std::vector<int> test = {1, 2, 3, 4, 5, 6, 7, 8};
std::vector<bool> foo = map(test, odd);
The first line should read:
std::vector<decltype(fun(T()))> result;
Then it also works with function pointers.
Wait, that only works if T is default-constructible. Better solution:
std::vector<decltype(fun(*(T*)0))> result;
template <typename T, typename Fun>
auto map(const std::vector<T>& source, Fun fun)
-> std::vector<decltype(fun(*(T*)0))>
{
    std::vector<decltype(fun(*(T*)0))> result;
    for (auto it = source.begin(); it != source.end(); ++it)
        result.push_back(fun(*it));
    return result;
}
Of course reserving enough capacity would also be a good idea before the loop:
result.reserve(source.size());
 
sbi
7:05 PM
@DeadMG Actually, I think C14 is some carbon isotope. ICBWT.
 
Good afternoon gents.
 
@sbi What does "ICBWT" stand for?
 
Quick question: does C++0x offer a nicer resolution for the most vexing parse?
By nicer I mean more intuitive.
 
I could be wrong though
hey, I had my account blocked for an hour
oh well
 
@DeadMG did you oppose Jeff?
 
7:08 PM
C14 is a carbon isotope, the one used in Carbon Dating
no
 
sbi
@DeadMG What for??
 
dunno, it didn't say, I checked my user page and there was no mention it
 
In other news, Carbon Dating is an awesome name for a dating site for geeks. Just sayin.
2
 
probably because I said that C was for fools in a fairly insulting fashion
 
sbi
@DeadMG Right, it's the one they use to date the remains of our ancestors.
@DeadMG Link?
 
7:09 PM
don't have one
 
sbi
@FredOverflow I thought "ICBWT" stands for "I could be wrong, though". ICBWT.
@DeadMG Aw. :( Stealing us the pleasure of seeing you dissing C. That's mean.
 
hey, I can diss C any time you like
specifically
 
@sbi Fuck. I thought it means "I can't be wrong though". Awkward.
 
I think that FredOverflow asked me what was in C1x, the upcoming C standard
and I said
"the fuck should I know, C is for fools anyway"
someone marked it as spam
 
@DeadMG I can't diss C. I think it's good for what it's meant for, which is programming for Unix. But it's not good for what people try to make it good for, which is roughly everything. Except for the fact that every conceivable library has a C binding. That's a huge plus. But other than that.
 
7:13 PM
@wilhelmtell C++0x offers the T a{}; syntax. Although that means something slightly different than T a = T(); if T has a genuine std::initializer_list constructor.
 
the hilarious thing is that it comes up on my screen as to whether or not I agree that it's offensive/spam/etc
 
@DeadMG I don't think it's enough to mark your comment as spam. I think there's a threshold, and even after that it takes a moderator or a few to agree with that.
 
@DeadMG Why would you want to date Carbon? Oh damn,@wil was faster :(
 
@wilhelmtell Yes and no. The syntax that leads to the most vexing parse is still allowed, but now you can use the same uniform initialization with the curly braces for all types, so as people start using the new syntax, it will be less likely to fall in the same errors
 
@FredO: Because living organisms stop recycling their carbon 14 after they die, but while they're alive they keep it in a very specific ratio
by measuring the ratio, you can tell how long ago any specific organic matter died
@wilhelmtell: Yeah, I know. The comment wasn't exactly pleasant, but I'm not sure that it warranted having my account locked
not that it seemed to stop me participating in the main site
 
7:15 PM
type t = {};
type t = { std::string() };
IIRC, the first will be equivalent to "type t;", while the second will call an 1 argument constructor that is able to handle a string rvalue reference.
 
nor was it locked until several hours after- that was easily this morning
 
@DavidRodríguezdribeas I don't believe that type t = {}; is equivalent to type t;, more like to type t = t();.
 
@DavidRodríguezdribeas @FredOverflow these don't quite do. Actually, where I get bitten most often is in range-initialization: std::vector<int> data(std::istream_iterator<int>(std::cin), std::istream_iterator<int>());
 
@wilhelmtell Most probably it requires more than one person to agree, I was given the option of flagging that exact comment as offensive and did not do so. Not that I endorse the language choice, but then again, I don't consider it offensive enough to flag it.
 
@wilhelmtell What happens when you replace the outermost parenthesis with braces?
 
sbi
7:19 PM
@wilhelmtell Well, I added a "ICBWT" to my interpretation, so you might be right. Oh wait. If you're right, then that would underline a wrong statement...
@DeadMG I think he asked why, not how. :)
 
there is that
 
@FredOverflow I'd expect to get a compiler error. A vector of ints can't hold stream iterators of ints.
 
Dude, I had too much lentils yesterday...
 
sbi
@KonradRudolph Have you looked at TBB? I think it comes with such an implementation.
 
@wilhelmtell Okay, you expect that, and what does the compiler actually do?
 
sbi
7:22 PM
@FredOverflow I think we did fine without you explaining your digestible problems which we didn't even know about until you blurted them out. (That would make it a real brainfart, no?)
 
@sbi I assure you, brain farts are not my most pressing problem right now... ;)
Also, I think you mean "digestive problems" ;)
 
@FredOverflow Heck, you are right... I read the FCD some time ago, and have not used C++0x at all (but in some trivial tests)
 
"Digestible problems" sounds like "small problems".
@DavidRodríguezdribeas The type t = {} syntax already has a meaning for arrays, and that should also apply to class types.
 
@FredOverflow
1  #include <iostream>
2  #include <vector>
3  #include <iterator>
4
5  int main(int argc, char* argv[])
6  {
7      std::vector<int> data = {
8          std::istream_iterator<int>(std::cin),
9          std::istream_iterator<int>()
10     };
11     return 0;
12 }

main.cc: In function 'int main(int, char**)':
main.cc:10:5: error: could not convert '{std::istream_iterator<int>(((std::istream_iterato
r<int>::istream_type&)(& std::cin))), std::istream_iterator<int>()}' to 'std::vector<int>'

make: *** [.make-debug/./main.o] Error 1
I can't think of any way to fix the issue without breaking backward compatibility, but I thought I'd be surprised.
But I do notice the compiler placed an extra pair of parens on the first argument in its error message.
 
Well, then you have to use the good-old "extra parenthesis" trick.
 
7:30 PM
lol
 
oh, didn't see that, lol
 
@wilhelmtell Well, I might have mislead you before with the syntax, that should be "std::vector<int> v{" without the "=" in between. Then again, it does not work. The problem being that the arguments inside the "{}" are not being matched (g++4.5) against the templated constructor. Is this an issue with the compiler? The standard?
 
@DavidRodríguezdribeas I'd expect a smart compiler to elide the copy. In fact, I think C++0x guarantees the copy would move.
 
@DavidRodríguezdribeas The "problem" is that std::vector<T> actually has a range constructor, so T a(1, 2, 3); and T a{1, 2, 3}; have different meanings.
If T has no range constructor, then both forms are equivalent.
(Not certain if "range constructor" is the right term.)
 
The error message offered different options for the constructor, including the range, but also offering other constructors
I am not sure what the standard should do. BTW, plain old syntax does work
 
7:41 PM
@DavidRodríguezdribeas It's not an issue with the compiler nor the standard. The value initialization is another form of initialization, similar to another constructor with fancy (uniform) syntax. It expects the same types of the vector and it will insert the objects into the vector. a stream iterator of int is not an int, hence the error.
 
std::vector <int> v( std::istream_iterator<int>( std::cin ), std::istream_iterator<int>() );
v.push_back( 5 );
 
How do you call a constructor that takes an initializer_list as an argument?
 
explicit = good, implicit = bad
 
compiles and does what you expect. Again, not sure on whether that is standard or g++4.5
 
@DavidRodríguezdribeas Isn't that a function declaration?
@FredOverflow Ah, I think it's called a "sequence constructor".
 
7:43 PM
@AlfPSteinbach I don't agree with this school of thought.
 
That is the reason for adding the push_back test. Had it been parsed as a function declaration, the second line would fail, as you cannot push_back into a function pointer
the line of code:
std::istream_iterator<int> it(cin),end();
std::vector<int> v{it,end};
fails, and the error message offers the following as possible candidates:
 
@DavidRodríguezdribeas Again, std::vector has a sequence constructor, so std::vector<int> v {it, end}; is interpreted as "I want a vector of integers, and the first two initial values shall be these two iterators." which obviously does not make sense.
 
Come to think of it
 
std::vector<_Tp, _Alloc>::vector(std::initializer_list<_CharT>, const allocator_type&)
std::vector<_Tp, _Alloc>::vector(std::vector<_Tp, _Alloc>&&)
std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&)
std::vector<_Tp, _Alloc>::vector(std::vector::size_type, const value_type&, const allocator_type&)
std::vector<_Tp, _Alloc>::vector(const allocator_type&)
std::vector<_Tp, _Alloc>::vector()
 
C++0x should allow for overloading uniform initializers.
 
7:48 PM
The indication of all those as candidates seems to hint that the compiler is considering {} as a potential match to any of them, not just the initializer list
 
@DavidRodríguezdribeas you're right. I see where you're going.
And I don't know.
 
why use that syntax when it's not supported by visual c++?
 
I'm going to dig into the standard draft.
... after shower. :p
 
@FredOverflow thank you
 
@AlfPSteinbach g++4.5 seems to have some support for it.
 
7:55 PM
I think that the key part of the standard is in 13.3.1.7, now, interpretation is required :)
 
@DavidRodríguezdribeas That paragraph numbers look almost leet...
 
When objects of non-aggregate class type are list-initialized (8.5.4), overload resolution selects the constructor as follows, where T is the cv-unqualified class type of the object being initialized:
— If T has an initializer-list constructor (8.5.4), the argument list consists of the initializer list as a single argument; otherwise, the argument list consists of the elements of the initializer list.
— For direct-list-initialization, the candidate functions are all the constructors of the class T.
@AlfPSteinbach Are you kidding? Or is this for real? If I was coding C in linux, should I avoid using dynamic array sizes just because MSVC does not support them?
 
@David: If you were coding C in linux, you've got bigger problems
 
@DavidRodríguezdribeas Just use direct-initialization syntax. Should work easy for your example. ;-)
 
for(int i=0; i<n; i++)
if(lineitem[i].quantity < q)
c++;

we can simply remove the inner branch and then get more efficient code:

for(int i=0; i<n; i++)
c += (lineitem.quantity < n)

However if we want to sum up the something (instead of just counting) we would have to

for(int i=0; i<n; i++)
total_price += lineitem.price * (lineitem.quantity < n)

So.. I wonder what's more expensive a branch or a multiplication.
I wonder what the cpu does with it, is a multiplication by 1 or 0 cheaper then lets say a multiplication by 13?
 
8:05 PM
I don't believe the second is indeed faster than the first.
You could get rid of the multiplication like this:
total_price += lineitem.price & -(lineitem.quantity < n)
Of course this assumes two's complement.
 
@FredOverflow depends on the selectivity, branch prediction works poorly when you have a selectivity of about 50% (randomly distributed)
 
@DavidRodríguezdribeas Sorry, for @WilhelmTell's example
 
Why the -?
 
I'd probably say that a multiplication is cheaper
a pipeline flush would be quite nasty
 
Will have to try it out..
 
8:07 PM
@Nils To convert 0x00000001 to 0xffffffff.
 
thx
heh just read that the Intel Itanium2 may executes both branches and then discards one result
 
@Nils I just compiled your code with -O2 -S, and as I suspected, both the " if ... c++" and the "c += ..." variant produce the exact same code, down to the last instruction.
int foo()
{
    int c = 0, i;
    for (i = 0; i < n; i++)
        if (lineitem[i].quantity < q) c++;
    return c;
}
The inner loop is:
L3:
xorl    %ecx, %ecx
cmpl    $98, _lineitem(,%edx,4)
setle   %cl
addl    $1, %edx
addl    %ecx, %eax
cmpl    $42, %edx
jne     L3
int bar()
{
    int c = 0, i;
    for (i = 0; i < n; i++)
        c += (lineitem[i].quantity < q);
    return c;
}
The inner loop is:
L7:
xorl    %ecx, %ecx
cmpl    $98, _lineitem(,%edx,4)
setle   %cl
addl    $1, %edx
addl    %ecx, %eax
cmpl    $42, %edx
jne     L7
That's because compilers are not morons.
 
cool thx, what compiler?
 
g++ 4.5.1
Just because you write an if in the source code does not mean that you will get a branch at the assembly level.
 
sure
 
8:28 PM
Gary Moore died today. R.I.P. Now playing with Lynnott again...
 
lol, that link is hilarious.
Question for you guys on editing a question. If the OP copy/pastes their entire program into the question, is it appropriate to prune it down to only the relevant parts (i.e. 100 lines ==> 10 lines)? My initial reaction is that at first it should be avoided (since no one can really know exactly what the OP was thinking), but once it becomes clear that the OP doesn't need 90% of the code to ask the question, then it should be OK to prune it down. What's the standard for this?
 
9:01 PM
1
A: What's a good computer to use for programming?

NilsA nondeterministic Turing machine lol

 
@Nils I learned a lot about programming on the Commodore 64. No design patterns or other modern crap, of course ;)
But useful stuff like sprite multiplexing.
 
hrmm I didn't have one! :(
 
Do any of you guys use git ?
 
sbi
@AlfPSteinbach You just made me pull out that Wild Frontier vinyl, rescue the record player from the accumulated sediments covering it, and play Over the Hills and Far Away.
I hadn't done this for a very long time.
 
@FredNurk LOL. it really reminds me of some answers on SO. :-)
 
sbi
9:11 PM
@Tony Don't you worry. I have never before heard the word. It's only used by the natives of a small and backwards region in Germany. :)
 
@Raynos it's still on my tolearn list, currently using svn
 
I did something stupid with git and dont know how to undo it
 
sbi
5 hours ago, by DeadMG
I don't drink at all
@DeadMG That would explain your, um, digestive problems. :)
 
lol
didn't mean anything, no alcohol :P
 
sbi
@DeadMG What do you mean, you "didn't mean anything"? :)
 
9:24 PM
I meant, I didn't mean I don't drink anything
I meant that I don't drink alcohol
 
@DeadMG your fail :P
 
@sbi It's very Scottish :-)
 
sbi
9:48 PM
@AlfPSteinbach What do you mean, Scottish? Because that uploader was so incredibly parsimonious with the resolution? :)
 
@FredNurk Ha ha ha ha ha. Tracer-T.
 
Hello! What are all you lovely C++ programmers up to this beautiful Sunday?
 
The same thing I do on every beautiful day that ends in "y": writing C++!
 
haha, nice
 

« first day (113 days earlier)      last day (4836 days later) »