« first day (658 days earlier)      last day (2198 days later) » 

3:50 AM
@DavidStone I think your proposal would benefit from outlining how these parameters interact across compilation units. Can functions with constexpr signatures have a c-style calling convention? Can they even be used outside the immediate compilation unit?
@nwp really might have been a better fit for the C++ lounge...
 
 
4 hours later…
nwp
8:10 AM
@Mikhail Blame puppy.
 
Ron
8:33 AM
If going down the performance route, what else apart from the algorithm optimization and use of profilers should I be aware of?
And container / algorithm theoretical complexity.
Strictly speaking about C++ code, not hardware related.
 
nwp
8:54 AM
Apr 12 at 13:31, by nwp
They mostly revolve around "You must benchmark and profile and know your hardware".
Supposedly most gains are from optimizing data structures
The algorithm becomes obvious once you have the right data structure. Which involves things like knowing that "zero is special" and that a cache line has 64 bytes and dereferencing pointers is expensive.
 
Ron
Awesome.
 
user6685907
9:07 AM
how do you remove an item from a map c++?
 
nwp
map::erase
If you ease elements in a loop you need to be a bit careful with the loop iterator like in the example.
 
@Ron everything runs faster on a gpu
 
eventually data motion will become your bottleneck
 
Ron
9:31 AM
I see. Appreciate it.
 
Sam
9:50 AM
Hi guys, I've got an Excel model which uses a c++ back end to generate a dll on build. This isn't my code base and to get to grips with it i'm trying to output some content from arrays which are being passed through the DLL. Using VS2017, the build works fine but I can't seem to observe any output when stepping through the following line of code
	for (int i = 0; i <= (sizeof(therapy1) / sizeof(therapy1[0])); i++) {
		std::cout << therapy1[i];
	}
I ran "Local Windows Debugger" and open the 'output' tab, but I don't get anything. I'm not a c++ programmer so I have no idea what to check
 
nwp
10:06 AM
(sizeof(therapy1) / sizeof(therapy1[0])) looks dangerous. therapy1 probably decayed to a pointer.
You should probably add std::cout << "Therapy 1 data:\n" before the loop to check if output works at all.
 
Sam
10:49 AM
That wasn't working either. After some research, I've found OutputDebugString() is allowing me to output a constant string. I haven't yet tried to pass in an element of the array
 
11:07 AM
@Sam it's definitely not <= either
Also, std::cout is buffering by default. You won't see the output until the program ends, you flush the buffer, buffer overflows, or you request a read from std::cin which is tied by default to std::cout
 
user6685907
11:35 AM
if i have a map
the map has a new item added to it at index 0
how would i stop this from deferenecing my map?
 
Ron
12:53 PM
Should the "A good read," wording be removed from the Bjarne's C++ book description?
I am glad that it got moved to the second place at least.
 
 
1 hour later…
2:00 PM
@Sam please don't do this use for(const auto & therapy : therapies)
 
Sam
OK sure. Is there a reason why?
 
@Sam Safer, less chance of dumb things happening. sizeof may not always return what you expect.
also your loop has undefined behavior
you're using <= instead of < this means you're exceeding the allocated size of the array.
 
Sam
Makes sense. Thanks @Mgetz :). Is there a right/wrong way for outputting variable values to the console? I've seen a lot of differing posts on SO
AH yes that was a typo. Someone mentioned it after it was too late to edit the text
 
@Sam no, my critique was of the loop, not the output
 
Sam
@Mgetz Just curious.
 
2:04 PM
depends on what you want to do. Buffering output to the console has performance improvements, so you could just do a '\n' after each of those and then do a std::cout << std::endl; after the loop to flush the buffer
 
Sam
I'm basically just stepping through someones code base to figure out what's going on
 
@Sam don't use console io for that. Use a debugger
altering the code in any way will change behaviors
 
Sam
Oh shoot. I've just been looping over arrays to observe the outputs
 
while this may not always matter, it can matter a lot if you're debugging an undefined behavior issue
because even minor changes can affect what the compiler does
 
Sam
Setting breaks in the code was just getting me memory locations for variables as opposed to their values. Sorry, I'm not a c++ programmer as you can probably tell
 
2:07 PM
moreover using a debugger allows you to directly inspect memory and see how things are actually happening
@Sam there are plenty of debugger tutorials out there
 
Sam
Do you know of a useful one for VS2017?
 
Sam
Thanks a lot for your help @Mgetz I'll have a read through now. Appreciate it
 
 
4 hours later…
6:03 PM
should lambdas be passed as a param to function as references, copies or forward?
 
Why does this loop keep breaking when I enter something other than 0? It should only repeat once and ask for another input, yet it goes into an infinite loop.

Here is a MCVE:
https://onlinegdb.com/SJMO9R46G
I fixed one error by adding another case for the 0
 
6:34 PM
@YvesHenri Depends. You'd usually be fine to take by value, as that's what the standard algorithms do / are allowed to do. I often take them by forwarding references or const&, though.
 
 
1 hour later…
8:01 PM
Hmmm.....
I have a tab delimited file with words that are separated by spaces.
So I'm trying to read in the file into some variables (searching for a substring)
	while(getline(input, line, '\t')) {
		if(line.find(partialAuthorName, 0) != string::npos) {
			istringstream ss(line);
			// Read in a line.
			ss >> authorName >> bookTitle >> ISBN >> EUID >> month >> day >> year;
			cout << "Author: " << authorName << "\t";
			cout << "Title: " << bookTitle << "\t";
			cout << "ISBN: " << ISBN << "\t";
			cout << "Borrowed Date: " << month << "/" << day << "/" << year << endl;
		}
	}
Is there a reason this is not working?
I think I read the getline properly for delimiting
 
8:16 PM
I'll try this.
 
8:36 PM
Didn't work.
 
8:52 PM
Also trying this:
	/*
	Variables that hold the book info.
	Use a stringstream to read in the line and process it.
	*/
	Book currentBook;

	while(getline(input, line, '\t')) {
		if(line.find(partialAuthorName, 0) != string::npos) {
			istringstream ss(line);
			// Read in a line.
			getline(ss, currentBook.fullName, '\t');
			getline(ss, currentBook.bookTitle, '\t');
			string ISBN;
			getline(ss, ISBN);
			getline(ss, currentBook.EUID);
			string month;
			getline(ss, month);
			string day;
			getline(ss, day);
			string year;
Throws an error with stol
So I'm totally lost right now.
 
@Annabelle debug and see what you're passing into stol
it's probably not an integer
 
9:05 PM
Hmm yeah it doesn't seem to be reading in properly
@Mgetz ok it fails past the first words
Jose Carey    Awakening The Beginning    21478649    NA    0    0    0
Example input ^
currentBook.fullName will have
Jose Carey
But after that there is nothing
 
9:24 PM
GOT IT
woops
 
 
2 hours later…
11:15 PM
Hmm okay so I seem to have an odd crash that I can't seem to work out
Even with a debugger, something bad is apparently being passed to the stol() in the search_by_student() function at bottom of file.
For example when I type in "smm1245" it should return a list of 4 ISBN numbers
Yet it does not?
Could anyone please take a look
 
nwp
Are you literally passing "smm1245" to stol?
 
no
stol should be reading in the third item in a line which is the number
sample output is
+----------------------------------------------+
|       Computer Science and Engineering       |
|        CSCE 1030 - Computer Science I        |
|   Student Name     EUID    euid@my.unt.edu   |
+----------------------------------------------+

1. Add
2. Check Out
3. Return
4. Search
0. Quit
Enter your choice:  4
What do you want to search with?
1. Author
2. Title
3. Student
Enter your choice: 3
Enter name:  smm1235

terminate called after throwing an instance of 'std::invalid_argument'
  what():  stol
But there should be 4 numbers returned, not just 2
 
nwp
> Exceptions: std::invalid_argument if no conversion could be performed
 
OH
Hm
 
nwp
Apparently you gave it something that could not be interpreted as a signed number. You probably gave it a letter.
 
11:28 PM
I don't get why it worked on the first 2 lines, but not latter 2
Lines don't change format
 
nwp
An easy way to check would be to print the text that you are about to give to stol. Or to use a debugger and just look at the value that failed to be converted.
 
when i changed the const value to 0, the conditional template still thinks it's the old value.
 
nwp
@Abra001 *((int*)(&b))=0; is UB. The compiler can randomly read the actual value or decide that there is no point because b can never change.
 
That makes doubts about the chaining of events.
@nwp yea, i read that g++ doesn't allow altering constant values.
But the variant passed to the conditional is not b, it is a content of its address.
 
nwp
11:32 PM
C++ doesn't allow modifying top-level constants.
 
11:56 PM
AH HA
@nwp for some reason it has an empty argument passed
To the function
 

« first day (658 days earlier)      last day (2198 days later) »