« first day (440 days earlier)      last day (2419 days later) » 

1:44 PM
The values in argv are "strings right"? So argv[5][0] would be the first character of the 5th arg?
Why then, when I say this does it seg fault?

char op = argv[5][0] // where argv[5][0] should be +, -, x, or /
 
2 messages moved from Lounge<C++>
are you actually passing 5 arguments to the program
 
./client 127.0.0.1 5 5 +
is what I'm using to test
That counts as 5 right?
 
weird, in old work I did I would do ./client serverIP portNO and checked for 3 arguments from the CLI
 
argv[0] is "./client", argv[1] is "127.0.0.1", ...., argv[4] is "+"
 
1:51 PM
oh shit
I'm retarded.
Thank you.
 
Hi Guys I got a question
About references to const in parameter list
void sorted (const std::vector<int>& vec)
{
	//std::sort(vec.begin(), vec.end());

	// print sorted
	std::cout << "Sorted list:\n";
	for (int i = 0; i < vec.size(); ++i) {
		std::cout << vec[i] << " ";
	}
}
We pass the vector by reference, so instead of copying the contents of vector, it can directly make changes, or use the values of members.
BUT we put a const there, so we cannot change the values of the vector right?
So that means we cannot sort the vector
So for sorting and printing inside the vector, I must pass by value. There is no other choice. Am i correct here?
 
well, you can pass by a non-const reference. of course this means that the original vector gets modified, which is what you may or may not want
 
i mean is there a way that i do not have to copy the values, yet i am able to print sorted elems?
i think its not possible
 
make a vector of pointers to int, sort the vector of these pointers by the pointed-to value, iterate over it
of course, in the case of ints it would be easier and more performant to simply copy the vector and sort it
but this may not be the case for more complex or larger types
 
2:08 PM
Ill try your approach and get back to you in a moment
@milleniumbug here will your approach have any advantage? Because size of pointer to int will be same as size of int
 
9 mins ago, by milleniumbug
of course, in the case of ints it would be easier and more performant to simply copy the vector and sort it
 
@milleniumbug your approach will be good for vectors of classes or bigger types?
whose member can be used for sorting
I mean a member of the class, something like int serial_no
 
@samjoe unless you really want to store initial order then sort (i.e. without using lots of additional memory) and then restore the order - you have little to next choice other than make a sorted copy.
 
@samjoe it could be more performant. if in doubt, measure
 
@EuriPinhollow Hm Thanks I understand! I too felt the same.
@milleniumbug Why does it say vec not declared in this scope?
void sorted (std::vector<int> vec)
{
	std::sort(vec.begin(), vec.end());

	// print sorted
	std::cout << "Sorted list:\n";
	for (int i = 0; i < vec.size(); ++i) {
		std::cout << vec[i] << " ";
	}
}
 
2:20 PM
@samjoe it is easy to tell if described approach will save you memory (you need to compare pointer size with object size) but if it saves you CPU cycles or not depends on compiler.
 
@samjoe you cannot have the code which you previously posted inside main.
 
@Euri I am not that stupid! Its outside main.
 
@samjoe I was debugging for loop whith semicolon inserted between the loop body and for() once, spent a good hour on it. I never said that you are stupid.
Considering that there is 99,9999% chance that compiler is more precise and has less bugs than you you should think twice before ignoring what it sais.
 
2:28 PM
Has happened with me too, and compiler didn't detect the semicolon :(
 
Anyways, this is not the problem with the code which you posted which is clearly outside main because there are no local functions except class methods.
And unless you post the whole code (or just the minimal code causing same problem) we can't help you.
 
I am so sorry I feel like a real idiot. The problem was on a different line and I was thinking it was in the function :\
 
Let me show you the whole code and my extreme idiocy
@EuriPinhollow Thanks for your answer!
@milleniumbug Thank you, at present I am unable to implement your method, Ill try it again after becoming a little proficient with pointers.
 
Two questions.
1. the question is more about C. Is there any analogue to following snippet in C (i.e. is that possible to have an object on allocated char array).? Due to C's concept of lifetime (starts on decalration/allocation function's return) I have doubts.
alignas(T) char store[sizeof(T)];
new (store) T;
2. Is this a good idea to copy uint8_t array with memcpy (what if CHAR_BIT != 8, is there any protection from standard for me on this case).?
 
2:38 PM
@GreenTree About the first one - all C types are trivially constructible, so aligned buffers can be declared by just doing T store;
otherwise C11 has _Alignas
 
@GreenTree "Is there any analogue to following snippet in C (i.e. is that possible to have an object on allocated char array).? " - yes but you will have to either call destructor manually or use smart pointer for that.
"2. Is this a good idea to copy uint8_t array with memcpy (what if CHAR_BIT != 8, is there any protection from standard for me on this case).?"
`char` can't be less than 8 bits long. If implementation has more than 8 bit chars it should take care of extra bits if it supports UTF8.
 
i meant is there any analogue in C. (the snippet provided is in C++).
@milleniumbug _Alignas(struct T) char[sizeof(struct T)]; and then single option is just perform type punning.
 
ah sorry
 
@GreenTree yes, it's ok to use memcpy for uint8_t (it's trivially copyable, and your concerns about CHAR_BIT are unwarranted)
 
@milleniumbug implementations should take care of that, so if they ever wants to implement UTF-? with different byte sizes it will matter.
 
2:47 PM
hey, I missed this: if CHAR_BIT isn't 8, uint8_t can't exist nevermind, not 100% sure about that one
 
uint8_t is not guaranteed to exist: http://en.cppreference.com/w/cpp/types/integer
and there is nothing preventing you from using just 8 bits of aby greater number of bits.
There is no problem in using existing implementation with bigger bytes except those relying on overflows and signed conversion unportably.
 
intN_t must have no padding bits, that is the problem.
 
That's why it is optional.
I.e. all fixed width types are optional: en.cppreference.com/w/cpp/types/integer
 
so the original statement was correct after all
if CHAR_BIT is not 8, uint8_t won't be defined
 
Correct but unrelated.
 
2:55 PM
also, memcpy copies in terms of unsigned char units so it literally doesn't matter, for standard purposes, char are bytes and char occupies a single byte
 
@milleniumbug from what statements you did such conclusion.?
that to your previous message.
 
 
5 mins ago, by Green Tree
intN_t must have no padding bits, that is the problem.
so does uintN_t
@GreenTree basically this one
 
Did you think that having istreams which report eof when it actually happens and not after the read fails is handy?
 
ISTR Kernighan ranting about Pascal which had IO working exactly like that
 
3:03 PM
@milleniumbug so did he like Pascal way?
 
@samjoe Most of the issues resolved. Read it closely. Think. ideone.com/P6c0OM Cheers
@milleniumbug I had mostly forgotten about those quirks
s/mostly/completely
 
I can't see how knowing eof ahead of failed read requires any overhead. Like, when istream is pipe input eof() can just block until pipe signals eof and when istream is file the implementation can check the file size against consumed data size. So, really, it is just the question about whether eof() will be blocking or not.
 
Do you even streams?
@EuriPinhollow How useful is blocking eof()?
 
3:23 PM
@sehe now that you asked me I got enlightened. I have a method which consumes input and I was checking for eof() prior to calling it. Instead I need not to check for eof(), I need to check the result of method.
So, it is not really important.
coliru.stacked-crooked.com/a/0d588dbab5fc2483 how do I fix it? I want to capture the local value at the moment of lambda initialization.
 
@sehe it does help that Turbo Pascal didn't have most of these problems
 
3:36 PM
Oh
auto f=[captured_local=local, captured_global=::global](){
};
@EuriPinhollow auto f=[captured_local=local, captured_global=::global](){};
@EuriPinhollow Otherwise, you can always make a ll factory: coliru.stacked-crooked.com/a/b5f45ba81c2c3397
 
@sehe appreciate ya.
 
@EuriPinhollow cleanest/shortest: coliru.stacked-crooked.com/a/817d8b7439ca3487
 
 
2 hours later…
5:24 PM
@Sehe Thank you for editing and sharing! I do not understand some of the advanced edits, but I will surely learn it eventually!
Really neat!
 
 
1 hour later…
6:37 PM
Is it OK to put empty constructors calling super constructors in header files?
 
nwp
Probably not. Show some code.
 
like struct Derived : public Base { Derived(int x) : Base(x) {} }; ?
 
nwp
@MarfGamer Looks reasonable.
 
as far as you're ok with putting this code in a header
 
6:40 PM
Normally I stay away from putting code away in a header
 
(a.k.a. you don't mind recompiling all the code that used CopyCat in case you want to replace 69 with 42)
 
However I'm not sure if this could cause undefined behavior or peoples code to mess up
Ah I see
I guess I'll just put it in a CPP with an empty body then
It seems like a safer bet
Thanks for the answer!
 
 
3 hours later…
9:59 PM
why cant i create hard drive handles with the CreateFile() function? it gives me error acess denied when i use PhysicalDrive0 witch is the disk
 

« first day (440 days earlier)      last day (2419 days later) »