« first day (289 days earlier)      last day (4661 days later) » 

12:17 AM
I know I can alias stuff with char*. Can I do it with unsigned char*?
 
Yes.
The Standards aren't clear on that but the general consensus is that it's fine.
IIRC the preferred C way is char*, C++ is unsigned char*. Don't ask.
 
 
2 hours later…
1:49 AM
Posted some nasty code on the Code Review site. Feel free to go there and laugh at it :)
 
 
3 hours later…
4:43 AM
not a dupe
0
Q: How to construct std::array object with initializer list?

HighCommander4 Possible Duplicate: How do I initialize a member array with an initializer_list? You can construct an std::array just fine with an initializer list: std::array<int, 3> a = {1, 2, 3}; // works fine However, when I try to construct it from an std::initializer_list as a data me...

he's deriving from std::array<>
 
5:07 AM
Hey, why is this chat room described as "Home of the Apes" ?
 
Lol. But is it a taunt on C++ or something?
 
It's just because of the conversation that preceded it.
 
Ok.
Hey listen , do u know how to make your own itoa function?
 
As a matter of fact, I do.
But why would I want to?
There's tons of existing solutions.
boost::lexical_cast being my favorite.
 
5:18 AM
Well I am currently working on g++ - arm and since the itoa function isn't standard its not provided with the standard library, the boost libraries will cause too much overhead on the puny embedded processor I am working on, so I need some simple solution.
 
Oh.
Do you have <sstream>?
If you do, you can use std::stringstream.
If not you need to do some math.
 
nope. its only something like "C with classes" , no STL , no nothing. only stdlib.h . :(
and
C++
I am not even sure if templates are supported
 
Ok, here's the gist. You make a loop and repeatedly take the remainder of division by 10. That's how you get each digit. With each iteration, you divide the original number by ten to basically "shift right".
 
i see, but how do u then convert it into a char* ?
 
Oh, itoa takes a base.
Use base, where I said 10.
 
5:22 AM
will casting work?
ok, base simplifies matters
 
You convert each digit to a char by adding it to the character '0'.
 
I see. Thanks. I'll work on the implementation.
 
Beware that this algorithm will get you the digits in reverse order.
 
then do u add the char* s with strcat?
 
Do you have <math.h>?
@burningprodigy No, you just put it in the right index.
 
5:25 AM
yes. and string.h is included thank god. so str functions work'
I see.
 
Ok, if you have math.h you can find out the length of the string needed with the log function.
 
ok. But should I reverse the string in the end?
since the digits would be in reverse order
 
Yes, that works.
 
thanks . I gotta go implement this now and make my app. Thanks and Good Bye .
:)
 
Bye.
Ah, also, take care with zero and negative numbers.
You may need to add special cases for those :)
And don't forget to null-terminate your strings.
 
6:20 AM
Yay. New avatar.
 
 
1 hour later…
7:47 AM
Morning Apes :)
 
Morning
 
@MartinhoFernandes I'm looking at your code, what is message() = delete; ?
 
It's C++11 way of saying the compiler should not generate a default ctor.
It's a bit redundant there, though, since I have another ctor.
 
7:52 AM
what strange syntax
 
Ok.
 
I like it. The ability to say that, not the syntax in particular.
You can do that for functions too.
void f(double d);
void f(int i) = delete;
The compiler won't let you call with an int. It won't do a silent conversion.
 
Wow, this solves a load of problems
I can't find moar docs about it
Do you have a link ?
 
I learned about this on Wikipedia.
I don't know of other links, though I'm sure there's a standard proposal somewhere.
And there's the standard itself, of course.
 
8:11 AM
This is...
21
Q: Is 0 a decimal literal or an octal literal?

ybungalobillZero is always zero, so it doesn't matter. But in a recent discussion with my friend he said that octal literals are almost unused today. Then it dawned upon me that actually almost all integer literals in my code are octal, namely 0. Is 0 an octal literal according to the C++ grammar? I'm just c...

... interesting.
 
8:45 AM
@MartinhoFernandes lol
 
 
3 hours later…
11:17 AM
@MartinhoFernandes This will be my first review: is copying your original code verbatim but intersparsing it with my comments good style?
 
What do you mean?
Ah, sorry I'm a bit slow.
I can't really tell, I'm new to that site.
 
Oh well.
 
But personally, I find it's probably a good idea, if the comments are not overly long.
Since the code is a couple hundred lines, it's better to have some locality.
 
11:38 AM
@MartinhoFernandes Are you working?
 
No, I'm on vacation.
I'll be travelling to back my hometown after lunch.
 
@MartinhoFernandes Are the explicit instantiations necessary btw?
 
Well, without them I'll have to put the template code inline in the header.
Since there is a limited number of possible instantiations, I figured I could use some partial compilation.
 
Well what about the message instantiations?
Wait let me read the code again.
 
namespace greed? :P
I don't like using ostream::write with an object casted into char* for serialisation too much.
 
11:45 AM
@MartinhoFernandes I see, where are you on vacation?
 
@MartinhoFernandes I'm pretty sure a lot of those instantiations are superfluous because your header already contains the type definitions and the implementation has the member defintions. Those are total specializations, not partial. (Your operator<< do need the explicit instantiations since it's defined in the implementation though.)
 
@ManofOneWay Right now, I'm at home, but I'll soon be at my hometown.
 
Also, wouldn't template <message_type M> std::ostream& operator<<(std::ostream&, const message<M>&); work?
 
@MartinhoFernandes nice =)
 
@CatPlusPlus Duh.
Stupid.
 
12:03 PM
@LucDanton You mean, total specializations get compiled without the need to instantiate them?
 
A total specialization of a member counts as a function definition, not a template definition. Or something like that.
 
Hmm, wasn't aware of that.
 
Try it separately to get the hang of it.
 
I blame amazon. My copy of C++ Templates: The Complete Guide should be here by now :(
 
Declare template<typename T> struct specialized { void f(); }; in a header.
Wait let me try it separately first to get it right!
 
12:09 PM
Oh, look, a first version of Perl was implemented with C preprocessor.
 
And it looks like Perl!
 
Declare template<typename T> struct specialized { static void f(); };
Define template<> void specialized<int>::f() {}
Compiles, links, runs.
(assuming a main that calls the specialization)
 
Oooops, I just realized a couple of casts there are wrong. I pasted the wrong version of the code.
 
O_O
 
I still don't like that casting to char*.
It feels dirty.
 
12:16 PM
@LucDanton Don't worry, it was a minor change.
@CatPlusPlus How do you serialize raw binary stuff?
There are only two unformatted output functions: put and write.
 
@MartinhoFernandes Well, like Boost.Serialization does.
Explicitly, for a lack of better word.
 
Can I control what the output looks like with Boost.Serialization?
 
@MartinhoFernandes How comes the data_type nested types aren't defined in your post? Brevity?
 
Yes, but you may have to write your own archiver
 
I.e. should we assume they're defined in your code?
 
12:31 PM
@LucDanton They are there.
 
@MartinhoFernandes Yeah, you just need to supply implementation of input and output archives, the default binary archives carry some metadata.
 
@MartinhoFernandes Got it.
 
@CatPlusPlus hmm, will look into that.
Seems like I need to spend more time browsing the boost docs.
 
Now that I think of it, I probably should drop my crappy integer serialisation and implement a proper wrapper around binary archives.
 
Don't use Serialization, you don't need it here.
I'd recommend Serialization if you need e.g. versioning.
 
12:34 PM
Hmm, I should be using types with explicit sizes.
 
Yeah I'm recommending that.
Also unsigned types.
 
I'm using unsigned but that's not guaranteed exactly 32-bits.
 
hey
 
I'm also not very happy with the signed char enum (I mentioned that in a comment).
Where are uint32_t and friends? <cstddef>?
 
cstdint.
 
12:37 PM
cstdint
 
uh
@CatPlusPlus something wrong with just istream >> t;? I don't see the point of that code
 
@DeadMG istream >> t doesn't read binary-encoded integers.
 
@DeadMG This uses locales.
 
Text-based representation doesn't work very well with game saves, we're already producing >20MB of data per save without compression.
 
Nevermind loading/saving times.
Hmm, I think I'll move operator>> to the header and have no explicit instantiations.
That way I can add extension messages (I'm planning to add at least the port message for DHT) without having to add an instantiation there.
 
12:56 PM
@MartinhoFernandes Answered.
 
Thanks for your time :)
And for not laughing :)
 
Got groggy by the end (I need my breakfast) so I didn't check conformance to the specs.
I generally want to question your sizeof() - sizeof() computations.
 
Oh, I didn't notice the unofficial spec had the sizes. I should pay more attention.
I did that to avoid computing it myself. I was lazy.
 
Yeah, but I wasn't sure what was being computed. I would have avoided the subtraction altogether and gone with sizeof(field1) + sizeof(field2) + ....
 
wow I've been missing out again!
damn you all!
 
1:04 PM
What? No one mentioned sex.
 
no, you just mentioned it?
I don't always wanna talk about sex, I wanna talk about other things too
 
Ok, thanks @Luc and @Cat for the thoughts, I gotta get going now. See ya.
 
see ya
 
2:02 PM
Dayum, it's already monday.
 
@EtiennedeMartel I know, weekend went by fast for me
 
@EtiennedeMartel so far from friday...
 
One of those weekends where you plan to get a ton of stuff done, but only half of it gets done
 
@0A0D Half is actually pretty good
 
@Drahakar yea, it's just too damn hot
 
2:04 PM
For me it was one of those weekends where nothing happens at all. It was nice.
 
Hm, this apple tastes weird.
 
@EtiennedeMartel was it shiny and red?
@EtiennedeMartel from a black witch
 
Nope, it was a company-sponsored Apple.
I'm starting to wonder if they like my work
 
@EtiennedeMartel They must not like it if that apple from them was poisoned.
 
If I suddenly stop writing, then it's probably because I was doing a crappy job
Or maybe because I started doing actual work.
 
2:09 PM
@EtiennedeMartel Yeah, right.
 
Wishful thinking, I know
 
@EtiennedeMartel less likely
 
Better drink my own piss.
 
@EtiennedeMartel more likely
:)
 
Well, this apple was good.
If it kills me, at least my death will be enjoyable.
 
2:14 PM
i do not believe any apple is worth death
but good luck living
 

« first day (289 days earlier)      last day (4661 days later) »