« first day (578 days earlier)      last day (2499 days later) » 

nwp
nwp
00:23
@Dariusz I don't really know about openmp, but if all you want is a parallel for loop std::for_each might be an alternative in C++17.
 
2 hours later…
02:19
Im at a lost, when I run 73 & 0x3 << 4 I keep getting 0... I expect it to be 16
 
2 hours later…
04:42
Hey guys, I have a question about this answer stackoverflow.com/a/12927220/1812249
Does thingOne and thingTwo have to be initialised in the constructor as shown? Or can it be done in some other function later?
you can change its value in another member function
yes, construction must be done in the constructor
you can assign a different value later, but that'll be just an assignment
what is your actual problem though
You just solved it : )
The problem is me trying to get my head around C++ classes.
Ok, here's a follow up question then: Why can other types such as an int be declared without a value and don't need to be assigned in the constructor?
not sure how to answer this in other way than "that's how this language works"
fundamental types are treated as if they were default constructible, but their default construction leave their values with a garbage value
and reading these is undefined behaviour
I gotcha, thanks.
I have a C background and have recently been looking at Python. So C++ is more complicated than C and less forgiving than Python so it has been a struggle.
04:53
this is a misfeature, but I assume this was done because C programmers trying to migrate their programs to C++ would complain about their performance being reduced
that said, one should enable all the warnings, and treat the usage of potentially uninitialized types as errors
Nov 29 '16 at 17:38, by milleniumbug
PSA: Enable warnings in your compiler if you haven't already (in gcc: -Wall -Wextra -pedantic)
Ah ok, I think I had that set, which is why I was getting my errors.
You should also explicitly set the version of the language with -std=c++XX in order to not depend on GNU language extensions accidentally
Yep, done (c+11), thanks.
(I use c++14, although I may switch to c++17 once the compiler support gets good enough everywhere)
I'm on a legacy project atm so I don't have much flexibility.
04:58
C++11 is good enough IMO most of the time
 
4 hours later…
08:57
The main time I really wanted C++14 when using C++11 is when using some of the standard algorithms with a map I think. It's simple enough to write [](auto const& arg) { ... } (or sometimes even [](auto const& lhs, auto const& rhs) { ... }) which requires C++14. In C++11 I have to remember the exact type, and I always forget the it's pair<Key const, Value> instead of pair<Key, Value>. Plus the type names easily get really verbose
nwp
nwp
09:20
Well, you could use std::map<T, U>::value_type, but yeah, it does get somewhat verbose.
Then again C++ tends to always be somewhat verbose.
typedefs to the rescue?
09:42
The wacky thing is that generic lambdas (aka [](auto param){}) seem to work in MSVC 2015
Also decltype(auto) is a weird feature because I'd think that regular auto should also keep the constant-ness
nwp
nwp
doesn't really make sense for return values though
10:39
Heyyo
Currently working in C and trying to concentrate four different values into one array position. I realise I am doing SOMETHING wrong and WHERE I'm doing it, but I can't wrap my head around what is actually going wrong.
Here's the relevant code. Any and all help is greatly appreciated!
Unless it's obvious to anyone looking at it, the first strcat seems to be the one causing issues. Though it looks perfectly fine to me
nwp
nwp
You overwrite the same memory repeatedly.
strcat returns the new end of buffer which you are not using.
Wait, actually it might be fine.
sprintf is the issue
it always fills from the start of the buffer
you need to update index so it points to where you want to fill, both strcat and sprintf will return a value to help with that IIRC
I dont mean to doubt you, but why does gdb in that case say "Program received signal SIGSEGV, Segmentation fault. [MemoryString] in strcat() from .. "?
do you ever clear history?
if not you basically have a leak
Not really, no
nwp
nwp
10:46
Did you run out of space in your buffer?
What's a history if you clear it though?
Not saying leaks are good, no matter what but..
nwp
nwp
history[index] += sprintf(history[index], "%d", n); should at least fix the problem with overwriting data
@Xariez Where are you allocating memory for the strings
@milleniumbug it's a global statically allocated char array
nwp
nwp
You also need to keep a pointer to the start of the entry somewhere.
10:48
Before you said that, the only code related to the history is in the gist. So nowhere.
@Xariez Exactly.
Right now, experimenting with something like this:
void init_history() {
  for(int i = 0; i < MAXENTITIES; i++) {
      history[i] = (char*)malloc(sizeof(char) * 50);
  }
}
Experimenting being a key word, mind you
@ratchetfreak yeah, arrays of pointers to char
that's still only a fixed number of entries
For now though, we can assume we will never go past "MAXENTITIES", if that's what you mean.
10:49
@milleniumbug oh I missed that
nwp
nwp
@Xariez You don't need the (char*) part and 50 characters might not be enough for the amount of data you put into it.
at least try and count how many chars you will need
Just a habit to have (char*). And probably not, but right now, the data we put in is static and 28 characters long
Oct 21 '17 at 16:42, by milleniumbug
remember that the code quality is inversely proportional to the number of casts in it
nwp
nwp
If you make it fixed size you can skip the malloc and just do static char history[MAXENTITIES][50];. But you will probably need to make it dynamic size.
10:52
@milleniumbug Can't fight that statement
@nwp Will do, seems easier
Neither sprintf nor strcat seemed to like that, however
nwp
nwp
Yeah, you will have to modify that a bit. Use char *current_position = history[index]; and then use current_position instead of history[index].
That also happens to solve needing to keep a pointer to the start of the entry around.
Hmm, logical.
I think.
[initialization from incompatible pointer type] - how lovely
oh wait
because im fucking stupid. 1s
static char* history[MAXENTITIES][50]; <- what more is there to say
nwp
nwp
After you are done you could put assert(current_position - history[index] < 50 -1); to have a chance to catch running out of space. And maybe use a #define HISTORY_SIZE 50 instead of hardcoding it so you can easily change it later.
@Xariez That makes a bunch of char *s and no memory to put history into.
Yeah, #define's are very handy (same goes for enum's, imo)
11:13
So after all of that, I'm trying to print the data at a requested position as well
char * get_history(int n) {
    return history[n];
}
However, when it comes to printing it, it only seems to print the ms variable - the last thing that get's sprintf:ed
Thank. You!
So two things I learnt today apparently:
while(history[index]) in cases like these, should be while(history[index][0]) - My guess to start from the beginning of the string?
And two, when sprintf:ing, you need to add the length of the current array position as well - Though apart from the buffer part, i'm not sure if it has any other use
Unfortunately have too much to do today to properly read through that, but will definetely "skim" through it. Thanks!
11:45
if I have a 100 miltion of items of struct in array. Would the memory consumption be a lot worse if I have a inline void function inside that struct or should I avoid that? I want to add clear() to clean up the struct.
nwp
nwp
Non-virtual functions don't add to the size of classes.
nice! So it should be
inline void clean(){};?
nwp
nwp
member functions that you define directly in the struct are inline by default, so you can leave that out
oh nice!
11:52
though whether a function is inline does not affect whether it will be inlined though
it's only a linker directive
 
1 hour later…
13:13
@nwp Nice read, thanks! Do you know any other good sources on C-strings?
nwp
nwp
No. I try to stay away from those.
@nwp But they're at the foundation..
you will soon find that the foundation of programming is horrible
nwp
nwp
So are transistor technologies. I don't want to deal with that.
@nwp There is a common sense boundary, just like with anything else. Transistors, IMO, are below that boundary.
@ratchetfreak That's a nice joke, but I may be doing *nix systems programming soon..
13:19
You can get quite far with passing std::string::c_str() or std::string::data() to functions
I'm not kidding, a lot of old "best" practices are now considered bad
nwp
nwp
Just because you are doing low-level things doesn't mean they have to suck. C++ is pretty decent at compile time zero cost abstractions.
@milleniumbug Probably I haven't given enough context. The linked Joel's article joelonsoftware.com/2001/12/11/back-to-basics highlights one of the possible pitfalls when using C-style strings (with C library functions).
yeah, which is why I don't use them
So, I'd like to keep reading in that direction, you see.
13:22
only std::string
heck, if I was using C, I wouldn't use them either
What would you use instead, then?
operating on them like buffers, that is, passing the pointer and the size separately
or combine those bits into a struct{char* buff; size_t length, cap;}
nwp
nwp
I'm not so sure implementing something like std::string in C is such a good idea. The coding convention overhead is pretty high and there is a chance you never actually need a capacity or much string manipulation at all.
yeah you either need cap or length but very rarely both
13:28
I'd say treat null-terminated strings not something you operate on, but rather as a serialization format
nwp
nwp
The normal way of profile -> find bottleneck -> optimize should be good enough to catch excessive string operations.
Then again if I was asked to profile some code I'd just have to type "profile c++ code" into my browser's address bar.
And if you need to do something more, get them to a useful data type first
nwp
nwp
After seeing this demo of a proper use of a profiling tool (?) I'm not even sure I could read much into those numbers that go beyond "x% time spent in function y".
I'm glad people like chandler carruth spend a lot of time figuring out what the right assembler code is and making naive code do the right thing so I don't have to.
CMake question... I have a couple of dependencies on some java code that build via gradlew. How do I tell CMake not to rebuild them each time I do a build? They don't need to be built often.
@nwp Second thank you, that's a great video for me.
So far I've only used vtune but that requires you to install one hell of a software distribution called "Intel Parallel Studio"..
Love how the author uses fish instead of a proper shell.
nwp
nwp
13:38
@Carlos CMake handles that for you automatically. If it doesn't you specified the dependencies wrong. Hint: CMake has a builtin for everything so there is probably a add_gradlew_source(${JAVASOURCES}) line that does exactly what you want, you just need to figure out what the name of the builtin is.
@iksemyonov fish is a proper shell...?
well, I switched to zsh with oh-my-zsh but fish is as good shell as any
@milleniumbug It most probably is, but the last time I came across it (being reviewed in a Linux magazine of sorts), it was dubbed somehow "basic" and "overly intuitive". But that was years ago.
@nwp aha I didn't realise that. I thought external_project was used to squish everything into shape
That said, at my last job I was pretty much the only person who actually cared about setting up an environment. I've come to learn that you can do a lot with putty, a mouse and a dumb editor.
Even with me starting to know basics of vim, I still happen to use nano from ssh from time to time
13:51
@nwp when I google it, all the results are for using CMake in gradle, not the other way round
nwp
nwp
Do you have to use gradle?
Also what's wrong with using gradle to use cmake? Doesn't that just solve the problem?
@Carlos Wait, are you calling gradle from cmake? Shouldn't gradle notice that the source is unchanged and do nothing?
Yeah I was wondering how you do that
I mean the Git repo doesn't change much
So why does it retry the build command?
@iksemyonov mouse is a luxury :D
I can give you a github link and perhaps you can tell me what the CMake config should be?
All you have to do when you install manually is clone it and run gradelw
nwp
nwp
13:59
@Carlos gradle probably has a verbose mode that makes it explain step by step why it is doing what it is doing
I'm not so experienced with java tools
nwp
nwp
Also check if just repeatedly typing ./gradlew makes it do a rebuild every time, in which case it would be gradle's fault (by which I mean you probably did something wrong in build.gradle).
@Carlos yeah it is unfortunate that neither this chatroom does :D
Yeah it does rebuild
nwp
nwp
so, fix your build.gradle so it stops doing that
14:03
aw man
 
2 hours later…
15:45
Iam working on processing gestures. I tried to code my approach here coliru.stacked-crooked.com/a/a538acb67495d337
the principle is to have a threshold which defines the time range where i collect data. if i hit the threshold i process the data, which means make a smoothing based on the collected data.
 
5 hours later…
20:18
so any tips/recommendations how to start with the networking in c++?
I haven't done networking in C++, so take whatever I say with a grain of salt. I know I've seen a couple cppcon videos on it, but I don't know if they'd really be useful to watch for this. Here's one by Michael Caisse on the Networking TS, maybe there's a Boost library that does a similar thing. I think there is a Boost library for networking, but I can't remember what it is
thanks I will watch it :3, also I heard something about boost asio, not sure how good is it thought
I think that's the boost library I've heard about
There may well be better libraries out there
yeah, like boost test and google test, most people use gtest :P
20:39
Hi Gentlemen I am new six pack muscle Joe in the c++ universe. Coming from the 10+ years java planet. Need help for struct vector serialization .. is anybody that can help me ?
struct objectv1 {
matrix<float, 0, 1 > obj_descriptor;
string person_name;
matrix<rgb_pixel> p_obj_chip;
string notes;

};

and :

std::vector<objectv1> object_deteails;
couldnt serialize / deserialize .. :(
you need some template for vector
but I don't know anything about writing from scratch serialization to help more: P
 
1 hour later…
nwp
nwp
22:06
@MichałKalinowski Do you want to learn about networking or do something productive like make a game multi-player?
@2adnielsenxxx Use a library such as cereal.
 
1 hour later…
23:25
@nwp need it for multiplayer TBS game :)
I have already written a base engine in opengl and without basic networking don't want go further
nwp
nwp
Do you want to have networking between players or only server and players?
well, server and clients sounds good
but I'm weak with that, what is the difference?
nwp
nwp
Player to player means players can cheat. Player to server means you need a server.
Synchronizing game state between players in the presence of delay is ridiculously complicated. In order to keep your sanity you should model it as only 1 game existing on the server and the clients have views of that game.
Once you are able to express the game state in bytes you are most of the way there. Sending bytes over the network isn't that difficult.
so server :D, and probably some serialization to send bytes?
nwp
nwp
That would be a relatively easy but inefficient way.
I got to go sleep. You can read this in the mean time to get a feeling for what you should pay attention to.
23:36
thanks man, I will do it, be sure, good night

« first day (578 days earlier)      last day (2499 days later) »