« first day (111 days earlier)      last day (4822 days later) » 

12:02 AM
Can you think of a smart way to get rand() to work with an unequal distribution?
Say, rand() % 4 with 25% chance for 0 and 3, 30% chance for 1 and 20% chance for 2.
 
the easy way? [0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2][rand() % 20]
(that's an array + indexing)
rand() & modulus should usually be avoided, though
2
 
Yeah, that's the only way I could think of. But I was wondering if there's a more performing way, in terms of space.
 
20 ints isn't exactly a lot of space :)
 
It's an example.
 
executable code size will likely be larger for less than 50 or so ints
 
12:07 AM
@wilhelmtell Pretty sure we had a question on SO on that matter.
 
But if O(1) space means re-inventing the algorithm then I'll stick with that!
 
the least you could get is O(n) with n in terms of probability+number pairs
 
You do not even need to keep the space. Just call rand() obtain the value in a big enough range that you segment appropriatedly. For the case (0,1: 25%, 2: 30%, 3: 40%) you can just do:
 
[(0.25, 0), (0.25, 3), (0.3, 1), (0.2, 2)] could be walked with a random number in [0, 1)
 
auto retval = 100;
oops
auto retval = rand(100);
if (retval < 25)
    //...
 
12:09 AM
int value = rand() % 1000;
if ( value < 250 ) return 0;
if ( value < 500 ) return 1;
if ( value < 800 ) return 2;
return 3;
 
@DavidRodríguezdribeas ah, that's a good idea.
 
but maybe i'm asking the wrong question, come to think of it.
in scrabble or an anagram game, do you think it's a good idea to give different letters different probabilities?
 
yes, should be roughly dependent on the (natural) language
scrabble in particular is very specific about what letters and how many of each go in the bag
 
yes, if you look at scrabble, it contains larger quantities of common letters like E
and then you pull out each tile at random
 
12:13 AM
I would expect to play with more E's than Z's
 
think about it
the alphabet is 21 consonants- 5 vowels
and one of those vowels is the rarely-useful U
that makes it an 80% probability of consonant
 
@DavidRodríguezdribeas I'd expect to have one of each, then it would be E-Z!
2
 
are my words 80% consonant? No, they're roughly equal mixes of vowels and consonants
 
E and T are 13% and 11% of all uses, from memory
 
12:15 AM
I wouldn't be selecting letters based on probability, I would put the appropriate amount of each letter in a container, shuffle it, and pop them off.
 
The last Scrabble game I played I spent the entire second half of the game with only vowels. It was awful.
 
yes, absolutely
you want to be sure that if you put vowels back in the bag, you're not gonna get a bunch back out
well, you can, but it's relatively unlikely
 
@DeadMG Tell that to the bag.
 
@JamesMcNellis ouiji
 
@Bag: I specifically want consonants, so fuck you
 
12:17 AM
I used to have an official scrabble dictionary easily accessible :(
 
heh, we used to play with them
I remember that we even had a 7, 8 and 9 letter word finder, which listed all acceptable 7,8,9 letter words with their components in alphabetical order
made getting 7letter words kinda cheap
 
@JerryCoffin: they actually fixed it before you answered :P
 
 
1 hour later…
1:31 AM
Hello everyone.
 
1:56 AM
hi
 
 
2 hours later…
4:09 AM
does anybody here know how to convert a std::string into a const char *?
 
c_str()
 
@FredNurk Oops -- thanks for the heads up -- deleted.
 
 
5 hours later…
9:26 AM
anybody know what can cause an error of this nature: c:\Program Files\boost\boost_1_44\boost\asio\detail\impl\win_iocp_io_service.ipp(442): error C2039: 'CreateWaitableTimer' : is not a member of 'operator``global namespace'''
it's not even my code!!!
 
9:44 AM
CreateWaitableTimer is a WinAPI function
that's pretty much all I know
finally came back with a diagnosis for my issues
 
and?
 
nurse says: bad diet
 
oh shit
 
that is, now that I'm the ripe old age of 20, I can't abuse my stomach like I could when I was 19 and expect it to work properly
 
what have you been eating? junk food?
 
9:48 AM
the same as when I first got here and my other year at uni and etc
 
@DeadMG Which is...?
 
mostly pizza with spices, acid drinks, etc
 
not healthy
 
okay, she might be right...
 
didn't expect that bad diet could cause crippling stomach problems randomly quite like that
 
9:52 AM
stomach is mostly related to stress. If you don't have any stress, bad diet seems quite likely.
Also, bad diet is always bad anyway, even if your stomach doesn't complain.
2
 
focusing on the immediate prolem here
 
@DeadMG You sound like a duct tape doctor ;-)
 
lol
you're not the one who can't sleep or eat
 
@DeadMG I used to have stomach problems for years (acid reflux).
 
fair enough
 
10:00 AM
It was never 100% clear what caused it, but my best guess is a mixture of too much drinking and an unhealthy degree of introversion.
You know, "swallowing" problems instead of discussing them. Stomach don't like problems, stomach like food!
 
lol
 
Yummy yummy!
 
 
1 hour later…
11:29 AM
tell me
why does this compile
int a[100];
1[a]=3;
if pointers, and array indexes are, in fact, NOT, the same thing
 
does not work here codepad.org/Plj7uVxf
 
@ChrisBecke because an array decays to a pointer as soon as you look at it in even the slightest way
a[1] does this, as does 1[a]
 
yes
 
@Drahakar That’s not a well-formed C++ program. You need the main method
 
based on the calculus that a[1] -> a+1 -> 1+a -> 1[a]
 
11:33 AM
haha silly me >.<. gosh
 
which means that, size_t, intptr_t, necessarily have to be the same size.
 
@Konrad yeah thanks :)
 
or the calculus would break
are bogus
 
@ChrisBecke No, they don't have to be the same. Consider this: unsigned char ch = 10; unsigned int i = 1000;, both are different sizes, but both ch+i and i=ch are correct
basically once the array decays into a pointer, you get the equivalent of:
int *p = &array[0];
and from there on, p+1 is of type int* and address one byte beyond the position of p, the same as 1+p. Note also that you can do: int array[10]; char ch = 5; array[5];
(darn, in the first line it should read: ch+1 and i+ch, not i=ch. It won't let me edit now)
Another example, in the opposite direction would be in a 32bit architecture, with 32bit pointers: int64_t index = 0; int array[10]; array[index];, which should also compile. The compiler is able to determine and convert the types appropriately
 
 
2 hours later…
1:18 PM
@ChrisBecke there's a much simpler reason for why that compiles: the standard says that 1[a] is equivalent to *(1 + a) and because 1 + a and a + 1 give the same result, you can do 1[a] or a[1]
2
 
1:43 PM
The 1[a]=3 example is rather classic, and understanding that it equals *(1+a) is good knowledge. Lots of people have strange believes that the array index syntax is better, or safer, than the pointer arithmetic version, for reasons unknown.
 
do they? I haven't run into that before
so many people misunderstand templates
that appears to be the best answer to a vague question, yet people get hung up in comments on words like "extra" and misreading "code size" as "source code size" rather than as "executable code size"
 
1:58 PM
There is actually a rule in the widely recognized MISRA-C standard stating that you aren't allowed to do pointer arithmetic, you must use array indexing, because it was regarded safer.
@Fred. Yep, there's a frightening amount of programmers thinking the number of source code lines is in direct relation to the size of the executable. So by that definition they would get smaller programs by using STL...
 
2:13 PM
@Lundin Either that or they are considering specifics cases. If you implement a C style vector type in a library keeping the contained objects by void* (or allocating space in the container, blah, blah, blah...) compile that into a dynamic library, the linker will leave all the code in the binary. On the other hand, when dealing with templates, only those member methods that are used are actually compiled.
If you only use: push_back, begin(), end() from a standard library vector, even if you use it for ints, doubles, ..., in some particular circumstances it might generate a smaller object size. Mileage will vary :)
In most optimization cases (whether it is for space, size of executable, speed) the fact is that you will always be able to find a counter example.
 
There was a stackoverflow page where I can see all advertisements at one place, where is it?
Does anyone know that? I am looking for a free component that once i found in ads
 
2:32 PM
Personally I find STL in general rather icky, but that's just me... As soon as I use STL, i turn horribly unproductive. And when you need an external tool to interpret the compiler errors, I think there must be something fundamentally wrong with the standard...
But then I'm actually a rogue C programmer sneaking in on the C++ chat >.>
 
2:43 PM
@LifeH2O the ads are listed in various meta posts; I also recall the page you mention, but can't remember where it is
@Lundin I agree, there are lots of problems with the STL; the containers are really solid, though
I used to use stlfilt, but I no longer need it – except for boost, which I don't recall it handling particularly well last time I tried
 
3:40 PM
@FredNurk thank you, this one is for open source, i remeber there were ads of commercial products too
 
sbi
1
Q: Performance impact of virtual inheritence

GraemeI am considering using virtual inheritence in a real-time aplpication. Does using virtual inheritence have a performance impact similar to that of calling a virtual function? The objects in question would only be created at start up but I'm concerned if all functions from the hierarchy would be d...

 
I'm not sure I ever saw a page for that
 
sbi
@FredNurk Except for a statement about OSS ads, this page is empty for me. What am I missing?
 
are you using an ad blocker? :P
 
user379888
Hi
 
user379888
3:49 PM
Can anyone help me out with the access of derived classes
 
@fahad what's the problem?
 
only if you ask a question
 
user379888
I don't get how does it all goes
 
you'd have to more specific then that
else I suggest you read a book :)
 
user379888
: (
 
3:51 PM
@fahad are you new to programming?
 
user379888
Not new to programming
 
user379888
I have a good experience with C
 
New to object orientation perhaps?
 
sounds like it
 
user379888
yes
 
3:54 PM
there's good tutorials online on this subject, and also lots of books exist on this subject, it's a bit long to explain in a chat
 
@fahad "I don't get it" isn't a question, so we can't even attempt an answer
 
@FredNurk I guess you could say that yes
 
if (!it.get()) { question.ask(); }
 
what's a better way to explain this to him? stackoverflow.com/questions/4887471/…
 
@FredNurk have not enough knowledge to help you there :(
 
4:01 PM
he's essentially confusing anything "done dynamically" with "dynamic memory allocation" (which, as I said in the comment, has a very specific meaning in c++)
 
4:28 PM
@FredNurk Show him an example of an allocator that doesn't dynamically allocate memory.
 
hmm, that's probably too complex to convince
lots of boilerplate involved
@PigBen: and now he's using wikipedia to justify his interpretation of what "dynamic memory allocation" means; I think it's a lost cause
 
4:44 PM
oh happy day!
one sour note, i had to downvote 5 seconds after logging on SO (it problematic with incorrect answers selected as solution)
but yet
 
wonder if that's better than just not being able to get through to two people in such quick succession
 
i think of communication as, when does one's best
 
like "X is far more efficient than Y", "no, actually, these are identical": stackoverflow.com/questions/4899992/…
 
if doesn't work, well one has done one's best
 
sbi
@FredNurk <slaps_head/>
@Lundin hey, C++ is not an OO language. It supports many paradigms, although OO is one of the better supported ones.
 
4:48 PM
@FredNurk actually there was a raging discussion some months ago about this over in clc++m. a person who maintained that he had to only to debug builds. and in those debug builds, function calls were expensive.
 
@sbi: but he was responding to confusion about derived classes and accessibility, which are about OO
 
the old discussion had mostly to do with (in-)efficiency of std::vector indexing
 
@AlfPSteinbach that seems simple to me: your enforced compiler settings suck, so of course the output you get sucks too
 
yes :-)
 
sbi
@FredNurk Ah. Been skimming over too much text in too little time again...
 
sbi
5:03 PM
@FredNurk FWIW, I've added my €0.2 to the discussion.
 
@sbi 20 cents? So you think your input is worth 10 times anybody else's? :-)
 
sbi
@PigBen Oh my. Well, I did put effort into that comment...
 
@PigBen No, it just means he has to lay down more on the table to have an audience.
 
user379888
is using a variable in dynamic allocative via new legal?
 
5:18 PM
@fahad what do you mean? complete code example?
 
user379888
int n=10,*p;
p=int*n;//legal?
 
user379888
sorry
 
user379888
My teacher told me that we can not use a variable in it as I have done
 
@fahad That statement is not legal, but I can't quite figure out what you are trying to do with it.
 
user379888
I am trying to allocate memory depending upon the users input which is n.The memory allocated will be n times int
 
5:21 PM
use sizeof
and besides
 
@fahad: that's invalid syntax, you probably want int *p = new int[n], which is legal
however, you should instead use vector<int> p (n);
 
user379888
Thankyou @Xaade and @FredOverflow
 
user379888
@FredNurk:thankyou
 
This would give you an array of bytes the same size as n * ints
int n=10;
BYTE* p = BYTE[sizeof(int) * n];
 
user379888
@FredNurk: BTW isnt that an array being allocated?
 
user379888
5:24 PM
@Xaade:good one!So you think that we can provide a variable in it
 
I mean... why would you do this though?
I have uses for it because we often send binary data over a pipe, so we allocate like this.
But if you wanted to access any int, you'd have to still cast it into an array of ints...
 
@fahad vectors behave as resizeable arrays, if that's what you mean
 
Or you have to memcpy back and forth.
@FredNurk Can you be sure than a vector will have the memory allocated as one block of binary data (like a CString)?
 
vector items are contiguous, guaranteed
 
cool, so can you copy out of a vector with a memcpy, or does it store some form of header data for items?
 
5:30 PM
@Xaade Yes, you can, with &v[0].
 
@Xaade only if the value_type is POD, since memcpy on non-POD types is UB
 
user379888
5:41 PM
Why Do We Need to Redeclare The Static Variable Of a Class Before Using it? I get the point that the class is just a template but still when a constructor is called and I am using incrementing the static variable in it.Why do we still need to declare it before main()?
 
@sbi, everyone: I created a tinyurl that might prove handy: tinyurl.com/so-cxxbooks
 
sbi
@FredNurk But how could I ever remember that URL? What I usually do is to go to the FAQ question page (I only type "c++-faq" into FF's address bar for that) and search for "guide". That I can remember and it gives me the URL.
Oh wait, you mean that, in comments with their limited size, that URL is smaller? That could be handy. I'm generally too talkative and often have a hard time cramping what I want to say into 500 chars.
Still, how can I remember this URL?
 
You're not redeclaring it..... you're defining it.

It has to be initialized. Since a static variable can be used without a class, you can't very well initialize it only in a constructor.

So you must initialize it at global scope.
@sbi You could make something that allows you to only put in the part past the slash.
 
sbi
@FredN: Ha, I solved that! Well, almost. I added a comment to the question. If that comment gets three upvotes, it will be default-visible. <shouting> Anyone care to upvote my comment for the greater good of Mankind? </shouting>
 
Which one???
 
sbi
5:52 PM
@Xaade The latest one, with the URL!
 
@sbi saw it after that......
Shame we can't move it up?
 
sbi
@Xaade Doesn't matter. If it gets one more upvote, it will be among the top five, and those are always shown.
 
sbi
Oh boy. There's almost 20 people here in the chat, but nobody is really listening. Hullo!
@AlfPSteinbach Ah! Thanks!
 
@sbi you're welcome
 
5:56 PM
Aren't the grey icon chat roomers AFK?
 
sbi
Yep. now it's among the top five and visible by default.
 
Now I will upvote everything else daily..... mwa ha ha ha
 
sbi
@Xaade Their checkin is long ago and/or they haven't typed in any message for a long time.
@Xaade You can upvote everything else exactly once, and there's only a handful comments with 2 upvotes already, which would hide my comment if upvoted further. And one more upvote for my comment will make it outshine them again. So the odds are all against you! :)
 
@sbi actually I mean remembering it :) it's much easier for me and wanted to share for anyone that might find it useful
@Xaade just inactive, no way to know if they're really afk
 
sbi
@FredNurk Yeah, those seemingly inactive users could watch our every message, but not reveal themselves as readers!
 
6:01 PM
@sbi: hah, I didn't even think of posting it as a comment there, nice :)
 
sbi
@FredNurk Now where's your upvote to this comment?
 
@sbi I could facebook spam, and give away FarmTown items for every upvote not on your comment!!!!!!
You know what people would do for a digital item with no real world value?!?!?!
 
sbi
@Xaade Yeah. As if the common facebook user has enough rep on SO to vote on comments! (And FarmTown - or wasn't it FarmVille? - I have heard of, but I suspect even less SO users among them.)
 
@sbi I ran out of votes 18 hours ago (and it is now 18:05 GMT, for reference)
 
Oh, rep can be earned....
 
sbi
6:05 PM
@FredNurk Haha, I know that!
 
I could post hundreds of questions on basic C++ stuff and tell them the answers....
 
@sbi but don't worry, I have it bookmarked to come back to :)
 
sbi
@Xaade Now you're stretching the idea far beyond its limits!
@FredNurk :)
 
The Karma would balance out because I'm learning them stuffs!!!!
MWa hahahahahahahaha
Actually.... it just made me think of something cool.
What if.
 
sbi
@Xaade You're teaching them. Learning is for when I teach you!
@Xaade Always a good question, that.
 
6:08 PM
You could create an elaborate digital nation of people with as much clout as a world leader country.
An internet alliance!!!
I have decided... Barbecue sauce is always an upgrade to Ketchup !
 
6:37 PM
meh, 113 rep for the day and I have to go out; looks like I break my streak of rep-cap days :(
 
oh noes
 
@DeadMG some of us are still trying to hit 10k for the tools :)
 
@FredNurk Happens to the worst of us. I deleted an answer with a couple up-votes late yesterday, so I only got 180 points (or something) even though I'd lost >100 points to rep cap earlier in the day...
 
meh
I played around with the tools for five minutes
never had cause to use since
 
@JerryCoffin you can manually recalc (bottom of the page) to fix that
 
6:43 PM
@FredNurk Yup -- gains me 20 points yesterday, loses ~300 for deleted questions I'd answered and such since the last re-calc... :-)
 
lol
 
7:04 PM
@sbi You mean "the greater good of nerdkind" ;)
 
you mean there are things that exist outside of C++?!
Our Standard, who art in ISO, hallowed by thy scripture. Thy compiler come, thy source code be done on CPU as it is defined in abstract virtual machine. Give us this day our daily templates, and forgive us our template errors, as we forgive those that twiddle bits. And lead us not into premature optimization, but deliver us from undefined behavior. Amen.
2
needs a better "as we forgive those that", but otherwise I like it
 
lol...
yeah... too many times do we c++ folks get stuck twidling bits ourselves
 
…and forgive us our bit-twiddling, as we forgive those template errors…?
 
doesn't sound right either
 
8:14 PM
Hi everyone
I need urgent help with doxygen. I offered a bounty, but so far there's no solution. I would greatly appreciate it if you can have a look: stackoverflow.com/questions/4840145/…
 
introduce carbon.
Then you have carbon doxygen.
But then you'll get more global warnings
3
 
8:33 PM
wow this is cool
wow, hey Fred
 
 
2 hours later…
10:38 PM
Hm.
 
10:54 PM
wtb sleep
 
@sbi I upvoted :)
 
11:40 PM
Interesting this page with the reputation... I don't quite understand the stats... I pressed the recalculate and I have lost some 300rep, nice job!
 
@DavidRodríguezdribeas I lost 47 :-)
 

« first day (111 days earlier)      last day (4822 days later) »