Click here to Skip to main content
15,399,959 members

Comments by Greg Utas (Top 200 by date)

Greg Utas 11hrs 5mins ago View
   
You're welcome. But like some of the other answers suggested, learn to use the debugger. It is the only way to find problems in more complicated software, so it's a critical skill that every developer must learn.
Greg Utas 23hrs ago View
   
I know what you're talking about (apart from the specific reference to ToS) but have never tried to develop this kind of software. My guess is that your computer has to generate the studies based on the feed of trades. If you don't want to write that software yourself, you'd have to look for an open-source version on GitHub or wherever.

EDIT: I will revise that from guessing to being certain. Even an SMA, for example, has a vast number of timeframes, and there's no way any system is going to feed updated results for each of them.
Greg Utas 2 days ago View
   
I've never used it, but the page that Richard linked to should give you the answer.
Greg Utas 3 days ago View
   
I'm an opinionated bastard. :)

By the way, the site that Richard linked to below is the one I use when I need to look something up about C++ or C. It's much more of a reference site than a teaching site, however.
Greg Utas 12-Aug-22 15:44pm View
   
Is this what you've tried, and it doesn't work, or are you posting an answer to your own question?
Greg Utas 9-Aug-22 8:01am View
   
I don't understand the question either. Either you left out some information or it is poorly worded. I'm guessing that there is an example (an array) that is supposed to produce the output that you've shown.
Greg Utas 7-Aug-22 10:11am View
   
It is considered inappropriate to post an answer to your own question, let alone mark it accepted. Instead, update your question with more information. You also received three responses, none of which you upvoted or marked accepted. Posting your own answer and then accepting it can be interpreted as none of those answers being valid.
Greg Utas 7-Aug-22 7:47am View
   
This is not an Answer, so marking it as "accepted" is inappropriate. It is standard for exceptions to be derived from a limited set of base exception classes.
Greg Utas 7-Aug-22 6:32am View
   
The "user" of your library is the application writer.

It's not so much the severity of an error as whether it is expected. The network being unavailable, or the destination being unreachable, is something that can happen even if the code is correct, so these things shouldn't be exceptions. They would be handled with if and errno.

As a library writer, it's unlikely that you should be dealing with threads and signals. That's up to the caller of your library.
Greg Utas 6-Aug-22 19:53pm View
   
"For the scenario being executed" referred to whether the user's code is correct in a particular scenario. If it is, it shouldn't have to catch exceptions.

Stroustrup's statement still leaves the question of whether an error is severe enough to warrant an exception. When an exception occurs in a live system, you need debugging information to help reproduce the problem. Specifically, you want a stack trace, and getting one is expensive enough that you don't want exceptions to occur in released code. When one occurs, it should be treated as a bug, and the code fixed so that it no longer occurs. Neither the library nor the user's code should cause them during proper operation. There are times that if statements and errno are preferable.

I've written an article, Robust C++: Safety Net, which deals with recovering from exceptions. You might find it useful.
Greg Utas 6-Aug-22 17:51pm View
   
By correct code, I mean correct for the scenario being executed. That doesn't mean correct in every scenario.

Stroustrup's guideline still leaves the design question of what a function's signature should be. If it can be designed to report a failure without throwing an exception, by returning nullptr for example, that is preferable. Returning npos or cend() from find follows this rule. But functions like front or pop_back can't do anything other than thrown an exception if a vector is empty.
Greg Utas 6-Aug-22 13:38pm View
   
Exceptions are provided to report errors from which it is impossible to recover. If an exception occurs, it should almost always mean that the code needs to be fixed. Because of this, many programs don't bother to catch exceptions. They just exit and leave it to the designer to debug and fix the problem. But it depends on the type of application. A game would just continue from where it left off. A server would clean up the current transaction and go on to the next one. It's not a question of whether code can be proven to be correct. The point is that correct code shouldn't have to catch exceptions. The library should only throw one when it has no other way to report an error. If code catches exceptions, it is either because it wants to be resilient or improve the way that it reports serious errors.
Greg Utas 6-Aug-22 12:13pm View
   
True. But my point is that once the code is correct, it shouldn't be necessary to catch any exceptions. This is a good way to tell whether your library is throwing exceptions appropriately.
Greg Utas 31-Jul-22 20:00pm View
   
If you've learned to use a debugger, you've taken a very important step.

Yes, each variable serves a different purpose--too many of them! You need one variable for the user's password, whether the user enters it or you generate it, and a second variable when the user retypes the password. That's all. But you have FOUR of them: password, pass, P, and userp.
Greg Utas 31-Jul-22 19:57pm View
   
A random string is an error. I don't think the code does what you want it to.
Greg Utas 31-Jul-22 16:16pm View
   
I prefer parentheses to make things clear, but it's correct. In descending order, the priorities are - < ? =.
Greg Utas 31-Jul-22 13:16pm View
   
That function call looks like the only place that affects the underlying buffer, so maybe the problem is in its implementation.
Greg Utas 31-Jul-22 11:41am View
   
Is m_stream the underlying stream? If that's what's getting corrupted, the only place this code affects it is in its read call. It looks recursive but I'm guessing it has a different implementation because read is a virtual function.

And is your space bar broken or something?! :)
Greg Utas 30-Jul-22 8:29am View
   
5. LOL.
Greg Utas 30-Jul-22 7:06am View
   
You haven't told us what your project is, so you can't expect to get any suggestions. If you do decide to tell us, you'll have to provide some details. One or two sentences probably wouldn't be enough information.
Greg Utas 29-Jul-22 11:31am View
   
I'm sorry, but this isn't a code conversion service. You need to make an effort before anyone will help you.
Greg Utas 27-Jul-22 5:53am View
   
Definitely better.
Greg Utas 24-Jul-22 9:24am View
   
What problem have you faced with scanf? You haven't told us.
Greg Utas 23-Jul-22 8:56am View
   
Thanks. But even just reading the code, there are a lot of issues.
Greg Utas 23-Jul-22 8:50am View
   
The code is understandable, but anyone who wants to compile this in order to help you will have to strip out all the line numbers. Please remove them.
Greg Utas 19-Jul-22 7:30am View
   
If you know the derived class, use static_cast. It has the same syntax as the ones that CPallini showed but has no overhead (dynamic_cast does) and isn't overkill (like reinterpret_cast, which should be avoided when possible).
Greg Utas 14-Jul-22 16:40pm View
   
So how did your multithreaded server work out? That's how I would also do it, so I'm not sure what you're asking.
Greg Utas 30-Jun-22 14:40pm View
   
I like auto because it saves typing (especially when template iterators are involved) and it keeps lines under 80 characters, which is what I prefer. But it sounds like you're new to C++, so what you're doing makes a lot of sense.
Greg Utas 29-Jun-22 17:51pm View
   
The compiler knows what the function returns, so auto will match the underlying type exactly.
Greg Utas 29-Jun-22 15:57pm View
   
I love auto, and eventually you will too. The compiler never has a problem guessing the correct type, but you have to be explicit when you want a reference:
const string& f();auto str = f();
and str copies the string, which is more expensive than saving the reference. To save the reference, you have to write auto& str....
Greg Utas 29-Jun-22 15:55pm View
   
Deleted
I love auto, and eventually you will too. The compiler never has a problem guessing the correct type, but you have to be explicit when you want a reference:
const string& f();
auto str = f();
and str copies the string, which is more expensive than saving the reference. To save the reference, you have to write auto& str....
Greg Utas 29-Jun-22 7:39am View
   
Yes, that's what the compiler will do when it instantiates the template. You can probably get around it by wrapping each argument in a class that effectively acts as a union.
Greg Utas 28-Jun-22 23:19pm View
   
You're right. It's ~(-1), not ~0, that will be interpreted as false.
Greg Utas 28-Jun-22 18:38pm View
   
I think it actually means i != 0, which will have the same effect. What amazes me is that some C and C++ programmers think it's brilliant to save a few keystrokes, so they write crap like this.
Greg Utas 28-Jun-22 14:53pm View
   
See the discussion above. If you can only count the same product once, more code is needed.
Greg Utas 28-Jun-22 14:51pm View
   
That statement was unclear, so I chose to ignore it! I though it might mean not to check both i*j and j*i, which is what the second loop seemed to be aiming at. If only unique numbers are to be counted, then a set or array of bools would have to be used to avoid double-counting.
Greg Utas 28-Jun-22 10:33am View
   
It should increment odd once because i == j.
Greg Utas 28-Jun-22 10:21am View
   
In your second loop:
if(a[i][j] % 2 == 0)
{
   ++even;
   if(i != j) ++even;
}
else
{
   ++odd;
   if(i != j) ++odd;
}
A different way to approach this is not to write any code at all. The product of two even numbers, or an even and an odd number, is an even number. The product of two odd numbers is an odd number. The multiplications are 1...10 x 1..10, so there are 5 odd numbers in each range. You should therefore expect 25 odd numbers and 75 even numbers.
Greg Utas 25-Jun-22 12:16pm View
   
Well done! You have learned one of the most important skills that a developer needs.
Greg Utas 21-Jun-22 11:29am View
   
5. And then the number of users of the pointer would be decremented when it was erased.
Greg Utas 15-Jun-22 6:44am View
   
I tried that as the first thing in my main but still the same result.

On an unrelated(?) topic, I have a test that kills a runaway thread with ctrl-C. It works on Windows but not on WSL2/Ubuntu. There is no sign of the ctrl-C getting forwarded to the Linux Console Window that VS2022 creates as a tab.
Greg Utas 15-Jun-22 5:59am View
   
Curious.
Greg Utas 14-Jun-22 19:48pm View
   
Each of your comments resulted in me getting 2 emails and 2 little red box notifications.
Greg Utas 11-Jun-22 17:29pm View
   
That was fast!
Greg Utas 11-Jun-22 9:43am View
   
What do you mean by "tracking"? An inventory of vehicles and their assignments? Or their current location, updated in real time? Something else?
Greg Utas 9-Jun-22 12:03pm View
   
I'd argue that insertion sort requires an array. But you've got a good point with tree sort.
Greg Utas 8-Jun-22 17:27pm View
   
Given that you have deleted your original question and entered a completely new one, my comment no longer makes sense. Do you realize how rude that is?
Greg Utas 5-Jun-22 7:41am View
   
If it's divisible by 100, it's not a leap year unless it's divisible by 400, in which case it is. 2000 was a leap year and will likely be encountered when running your program.
Greg Utas 3-Jun-22 17:43pm View
   
5. Thanks for the info. I'm going to proceed with the default priorities and see how things turn out. I think it has a good chance of working even without them.
Greg Utas 3-Jun-22 8:13am View
   
A real-time system needs priorities. A scheduler that doesn't have them is ill-suited to the purpose. It works fine on Windows. On Linux, privileges, not a lack of support, seems to be the problem.
Greg Utas 3-Jun-22 7:31am View
   
I'm not so concerned about the app's priority as the relative priority of the threads, and that looks like it's going to be difficult. See my recent comment to k5054 below.
Greg Utas 2-Jun-22 19:14pm View
   
It looks like there will be an issue with thread priorities:

https://man7.org/linux/man-pages/man7/sched.7.html states

For threads scheduled under one of the normal scheduling policies (SCHED_OTHER, SCHED_IDLE, SCHED_BATCH), sched_priority is not used in scheduling decisions (it must be specified as 0).

So unless SCHED_RR (or SCHED_FIFO) can be set, it looks like lowering some threads' priorities will have no effect, or that it may not even be allowed.
Greg Utas 2-Jun-22 18:56pm View
   
It can set various limits, but there isn't one for priority.

https://man7.org/linux/man-pages/man3/getrlimit.3p.html

EDIT: What's with this bunch? There's another page where the nice value can be changed:

https://man7.org/linux/man-pages/man2/getrlimit.2.html
Greg Utas 2-Jun-22 16:25pm View
   
Thanks. Never heard of it, but I'll look into it. This is the first time I'm using Linux.
Greg Utas 2-Jun-22 12:31pm View
   
Thank you for your detailed response. Lower the priorities?! That's a great idea. A deployment could then presumably use setcap to raise the process priority. It's the relative thread priorities that are the key in any case: if those are correct, then I basically control the rest of the scheduling anyway, so I think it will work.

I'll let you know how this works out. Maybe lowering the priority needs permission too. :)
Greg Utas 1-Jun-22 9:56am View
   
You're going to have a problem when you change this. You define marks[4] but then check i < 5. This will lead to using marks[4], which is out of bounds. The index for an array defined with [n] goes from 0 to n-1.
Greg Utas 29-May-22 19:33pm View
   
That's not passing references, but pointers. References would be int& sum and int& average.
Greg Utas 29-May-22 8:25am View
   
And should a projection of the line (a) bisect the hexagon through two vertices, (b) through two edges, (c) form one of the hexagon's sides, or (d) I don't care as long as it's a hexagon! Decisions, decisions. :)
Greg Utas 27-May-22 11:09am View
   
Grazie. I usually find those details when the compiler complains. :)
Greg Utas 27-May-22 8:03am View
   
Yes, this is unambiguous. But you could just stick to your original constructor, with its two defaults. The only difference is that your original code allows a ClassOne to be constructed with *one* argument (x), with y still defaulting to 0. I don't think that's a useful capability, or even appropriate, so I prefer your new version. But I wouldn't bother to forward from the ClassOne() constructor to the ClassOne(int, int) constructor. I'd just initialize x and y to 0 right in the ClassOne() constructor, which is more efficient.
Greg Utas 27-May-22 7:34am View
   
The reason that the ClassOne(int, int) constructor was selected is because both of its arguments specify 0 as a default. So if an instance of the class is declared without arguments for the constructor, that constructor will be selected. I think that if you actually declared a constructor that took no arguments, the compiler would generate an error saying that your code was ambiguous: it wouldn't know which constructor to select, because both could be invoked without arguments.
Greg Utas 26-May-22 14:17pm View
   
Kind of strange, because serial killers are always referred to using three names. :)
Greg Utas 26-May-22 10:40am View
   
PIEBALDconsult has flagged this member in the Spam & Abuse forum. The original post seems to have been edited but is still inappropriate, and your article has a second one from the same member. Please ignore the troll.
Greg Utas 26-May-22 6:57am View
   
It's very unlikely that you'll get any help unless you show some code that you wrote. This isn't a "please do my assignment" website.
Greg Utas 26-May-22 5:57am View
   
I hope somebody finds it useful. :)
Greg Utas 20-May-22 15:05pm View
   
It's unlikely you'll get any help unless you provide more details as to what error you're getting. A compile error? A link error? A run-time error? Or it just doesn't do what you want? At least you have comments that suggest you're working on a binary search tree, but that's all we know.
Greg Utas 18-May-22 9:58am View
   
Right you are. When I see an #include, I just assume. :)
Greg Utas 18-May-22 9:49am View
   
You tagged your "question"--I use the term loosely, because it's a request for us to write all the code for you--as Python, yet you've "tried" a C++ header?
Greg Utas 16-May-22 20:49pm View
   
I haven't used this requires is_same<> stuff, but I'm guessing that it shouldn't be repeated in the function definition. Also, if U is a parameter to that function, won't you have to give it name for the function to be useful?
Greg Utas 8-May-22 10:10am View
   
I doubt anyone will do this for you even if they wanted to. First, you haven't even told us what this game is. Second, how can a flowchart be placed in a comment?
Greg Utas 6-May-22 17:43pm View
   
Show us your code then.

Although I use C++, not Java, I doubt you need to use strings. If you divide an integer by 10 in C++, and I assume in Java, it is the equivalent of removing the last digit. It doesn't get rounded up, but truncated.
Greg Utas 6-May-22 15:02pm View
   
Maybe the software that initiates the scaling thinks that your jobs must be stateless, which is the mindless fashion these days.
Greg Utas 4-May-22 15:22pm View
   
If three nested loops are needed, why worry about it? There isn't much happening within each loop. Tools that generate metrics are hardly infallible.

That said, I don't know Go--which means that your code isn't "commented". If it was, I'd know what it was trying to do and might even be able to offer a useful suggestion. There are two brief comments, neither of which does much to explain the code. You're looking for matches in customer data using filters, and this requires a sort for some reason.
Greg Utas 4-May-22 13:33pm View
   
You're welcome.
Greg Utas 3-May-22 8:41am View
   
I don't know how to write these scripts, but the more information you provide, the better the chances of getting an answer.
Greg Utas 3-May-22 7:15am View
   
You have answered two of the questions. If 0 is included, the first argument will be n=0. The function will only call itself if n<=50. So how will it change n each time when it calls itself? You need to do this yourself. I don't think anyone here will just give you the solution. It would be unethical.
Greg Utas 2-May-22 18:43pm View
   
200 sockets is a lot of sockets for a client. That's like running a little server! But I can't really say without knowing more about what you're doing. I also write C++, not C#, though that may not be relevant here.

As far as "interference" on a single socket goes, the question is whether the server or your client is causing it. I'm guessing it should be possible to use a single socket. But to do so, you need to be able to forward an incoming event to the code that sent the request. Unless that event does something like echo an identifier that you sent with the request, forwarding it to the right place will be hard unless you know that a given event should always be routed to a specific requester and can hard-code this.
Greg Utas 2-May-22 14:14pm View
   
To have any hope of getting an answer, I think you'll have to provide more details about how often these logs are supposed to arrive, where they're stored, where the list of clients is maintained, on so on.
Greg Utas 1-May-22 11:21am View
   
True. But he posted a follow-up "code plz" question which revealed that this was for an exam that specifically requested him to demonstrate a unary operator being implemented as a friend. That question was subsequently closed for not being a proper question.
Greg Utas 1-May-22 7:52am View
   
Code needs to be there for a reason. If you removed the getch, you could also remove the #include conio.h. But then your program would exit immediately after performing its work, so you wouldn't be able to inspect what it had done. The getch is basically there as a debugging breakpoint. First time I've seen this. :)
Greg Utas 1-May-22 7:41am View
   
I was wondering what the getch at the end of your code was for and then realized it's probably just to stop the program from exiting until you enter something on the keyboard.
Greg Utas 1-May-22 7:34am View
   
Your code looks legal to me. I can't say whether it's complete, because that requires knowledge of what it's supposed to do. Unless you're specifically practicing the idea of implementing an operator overload outside a class, which can be useful for binary operators, I would just implement operator++ within the sample class. But its definition would then look different (no need for friend or the ob2 argument). It also needs to return a reference to the object. And there are two versions of operator++: prefix (which you have here) and postfix. Please read https://stackoverflow.com/questions/3846296/how-to-overload-the-operator-in-two-different-ways-for-postfix-a-and-prefix.
Greg Utas 1-May-22 7:26am View
   
Leaving out the & will result in a copy of the object being passed to the function. The work will be done on the copy, not the original object. To have the work done on the invoker's object, the object must be passed by reference. That is, the function receives a reference (secretly a pointer) to the object, which allows the work to be done on the external object rather than a copy.
Greg Utas 15-Apr-22 9:24am View
   
5, partly for being so kind. :)
Greg Utas 14-Apr-22 7:54am View
   
Gerry's suggestion is a good one. An alternative would be to draw a dashed line between the points where the signal was lost.
Greg Utas 14-Apr-22 7:50am View
   
I think the ladder would normally be displayed vertically, with asks above and bids below, with the number of bids or asks to the right of those numbers. The price of the last trade would be displayed separately. A histogram of volumes at each price is also useful but relies on historical data.
Greg Utas 28-Mar-22 7:41am View
   
I don't think you've posted the entire assignment. All the program has to do is input a bunch of data? Then what?!
Greg Utas 24-Mar-22 15:19pm View
   
You may find this helpful: https://www.cprogramming.com/reference/preprocessor/__FILE__.html.
Greg Utas 24-Mar-22 13:35pm View
   
You have to change the log system to add a filename (const char*) to each logging function, and then define a SetLogsForFile(const char* filename, bool onoff) function that front-ends a database that each logging function consults to see if the log should be suppressed.

That repository has a lot of code written by someone who knows how to code. If you just cloned it and want to play around with it, you should take on something easier first.

I am NOT writing the code.
Greg Utas 24-Mar-22 13:34pm View
   
Deleted
You have to change the log system to add a filename (const char*) to each logging function, and then a SetLogsForFile(const char* filename, bool onoff) function that front-ends a database.

That repository has a lot of code written by someone who knows how to write code. If you've just cloned it and want to play around with it, you should take on something easier first.
Greg Utas 24-Mar-22 12:39pm View
   
No. You didn't even tell me where myExample.cpp is located. I looked a bit but couldn't even find it! Stop wasting people's time.
Greg Utas 24-Mar-22 12:19pm View
   
There's a lot of code in there. I doubt anyone will sift through all of it and do this for you.
Greg Utas 24-Mar-22 7:10am View
   
You haven't told us what the errors are. You say there are no errors, but then you say that F5 finds 4. We don't even know what F5 does. Does it compile your program? Run it? If it only compiles it, then getting your program to compile is only the first step in getting it to work. A program of this size will probably contain execution errors, and you'll have to use a debugger to find those.
Greg Utas 22-Mar-22 8:05am View
   
What do you mean by "check the connection". It will certainly fail if the socket handle isn't valid, but that's about it. Because it only reads the keepalive option, it won't detect whether the socket is connected or whether a disconnect is pending.
Greg Utas 21-Mar-22 10:52am View
   
Then post what you've done and explain how it "breaks" your code. It could mean a compile error or a bug in running code. If it's the latter, you need to learn how to use a debugger, which is practically the only way to find and fix problems in non-trivial code.
Greg Utas 21-Mar-22 9:20am View
   
This is not your code, but the starting code that you've been given for your assignment. You haven't even added any code for the SAVE command, for loading the employee records from a file based on a command line parameter, or even stubs for the functions writeEmpToFile and readEmpFromFile. To put it bluntly, you're asking us to do all of your homework, and it's very unlikely that anyone will be willing to do that.
Greg Utas 18-Mar-22 9:00am View
   
Just writing name here is certainly more idiomatic and what you'd usually see.
Greg Utas 18-Mar-22 8:37am View
   
When you have more information about your original question, please just edit your question and add it there. This isn't a Solution and, even if it was, it's considered inappropriate to post a Solution to your own Question.
Greg Utas 17-Mar-22 12:57pm View
   
When you're running code this size and it doesn't work, it's time to learn how to use a debugger. You can't expect someone else to analyze or debug non-trivial code for you. A debugger lets you stop your code at whatever line you want and step through it a line at a time to see what's going on. It's the best way to find bugs in non-trivial code.
Greg Utas 17-Mar-22 9:57am View
   
You type faster than I do. :)
Greg Utas 17-Mar-22 9:12am View
   
5.
Greg Utas 16-Mar-22 20:08pm View
   
You're welcome.
Greg Utas 16-Mar-22 19:28pm View
   
LOL
Greg Utas 16-Mar-22 19:10pm View
   
But judging from the other answers, the & may not be needed, probably because str is an array and decays to a pointer. I've only written C++ and have never used scanf, so I'm unfamiliar with its vagaries.
Greg Utas 16-Mar-22 16:47pm View
   
5. Sadly, I don't think the debugging part will be needed after the & is added.
Greg Utas 16-Mar-22 16:28pm View
   
I know nothing about this topic but noticed you have several divisions by 64 in a nested for loop. If the compiler doesn't generate >> 6 for these, it would help to do that yourself.
Greg Utas 16-Mar-22 11:27am View
   
I do! You'd be amazed at some of the stupid mistakes I have to debug!
Greg Utas 16-Mar-22 11:27am View
   
Deleted
I do! You'd be amazed at some of the stupid mistakes I have to debug!
Greg Utas 16-Mar-22 8:47am View
   
Which probably means that there will be a follow-up question. :)
Greg Utas 15-Mar-22 18:16pm View
   
I wanted to leave the generation of the random number up to the poster, but you're quite right about the circular queue! I didn't read it carefully enough.
Greg Utas 10-Mar-22 16:11pm View
   
All this is Windows-specific. I use very little Windows stuff in my C++ code, and none of what you're using. You have to make sure that you've set up your Properties file to include the libraries that define these namespaces.
Greg Utas 10-Mar-22 9:42am View
   
I think that explains it, but you will probably have to show some code if you expect to get help.
Greg Utas 10-Mar-22 9:22am View
   
I can't even understand what the code is supposed to do. Regardless, you will probably have to show some actual code that you've written to try and solve the problem. It is unlikely that anyone here will write the code for you.
Greg Utas 7-Mar-22 12:16pm View
   
LOL
Greg Utas 7-Mar-22 8:42am View
   
5. I don't have your patience. :)
Greg Utas 26-Feb-22 14:57pm View
   
This is the kind of project that would be expected in a serious operating systems course. You can't possibly believe that anyone here is going to write this code and just give it to you.
Greg Utas 31-Jan-22 20:29pm View
   
Redefining a keyword is naughty. And many uses of #define are undesirable. It's fine in your own code, but not in code that others also use.
Greg Utas 31-Jan-22 11:32am View
   
You're welcome.
Greg Utas 31-Jan-22 10:51am View
   
It's not going to fix your problem, whatever it is, but exceptions should be caught by reference: catch(int& err). It won't matter for an int, but it can be important when the exception is an object.
Greg Utas 30-Jan-22 9:05am View
   
You can cast to whatever you want, but you risk blowing up if you
(a) use delete on a pointer that isn't the first vptr in the original object, or
(b) access a data member when there is another vptr in between.
Greg Utas 29-Jan-22 9:31am View
   
Thanks!
Greg Utas 29-Jan-22 6:43am View
   
Ah! Then you need to take out the #ifdef and #endif, and replace the #else with an else.
Greg Utas 23-Jan-22 8:08am View
   
Yes, I thought that was certainly possible.
Greg Utas 21-Jan-22 21:11pm View
   
I can't see the need for more than one socket unless you're communicating with different servers, when it might simplify things. Separating the socket (I/O) from the application is still a good idea because the I/O thread waits on the socket and the application thread waits for user actions like keyboard inputs or mouse events. When using more than one thread, watch out for critical sections! Part of the motivation for separating things is to keep each thread focused on a single job, without having to multiplex various responsibilities.
Greg Utas 21-Jan-22 8:25am View
   
It looks like you're trying to do GUI stuff on multiple platforms. I don't do GUI stuff, but I would try https://www.wxwidgets.org/ if I did. Open-source and free.
Greg Utas 21-Jan-22 7:57am View
   
I see that others have explained why constexpr can't be used for this purpose.
Greg Utas 7-Jan-22 15:56pm View
   
#if(0) is the same as #if 0, but I don't know what $if 0 is.

I think if(0) will compile what comes after the if, but you'll probably get a warning about unreachable code, and the compiler might be allowed to ignore that code.

What id 0 has to do with this, I don't know. It won't compile.
Greg Utas 4-Jan-22 12:29pm View
   
Doing this is a good idea. main should be kept fairly small. By moving pieces of it out into other functions, you break up the software into smaller, more understandable pieces that you might even be able to reuse. It also makes it easier to understand and evolve main itself.
Greg Utas 3-Jan-22 10:19am View
   
See std::unordered_multimap.
Greg Utas 3-Jan-22 7:42am View
   
Many containers that use hashing allow for collisions.
Greg Utas 28-Dec-21 6:47am View
   
5. Finding the MST sounds like a good way to start. See my above comment.
Greg Utas 28-Dec-21 6:45am View
   
See Solution 2, which may significantly help to optimize the code. If you find the minimal spanning tree and then do what I suggested, I think you'll find the same walk as if you applied my suggestion to the entire graph.
Greg Utas 26-Dec-21 18:43pm View
   
The algorithms that you mention deal with spanning trees, but it sounds like you want a path. Is that correct?
Greg Utas 26-Dec-21 9:14am View
   
I didn't look to see if a constant for pi was already defined in math.h.
Greg Utas 23-Dec-21 7:18am View
   
Thanks for pointing these out. Looks like I'll no longer be watching cat videos!
Greg Utas 21-Dec-21 13:58pm View
   
The time complexity of a sort algorithm is usually based on the number of comparisons.
Greg Utas 15-Dec-21 8:15am View
   
5, but you're spoiling him. :)
Greg Utas 11-Dec-21 7:27am View
   
If you've got the IP addresses and other details correct, see if the desktop has a firewall that is blocking incoming packets.
Greg Utas 26-Nov-21 18:48pm View
   
It appears to be a reference to one of his previous questions[^], where Richard contributed Solution 3.
Greg Utas 26-Nov-21 18:45pm View
   
It sounds like he wants an explanation of what the code does.
Greg Utas 24-Nov-21 7:27am View
   
Although the assignment didn't ask for it, the reason for defining a Date class, as suggested in Solution 2, is so that its constructor can check for illegal dates like April 31. Exactly what to do if such a date is specified depends on the program, but usually the constructor would use the throw operator to raise an exception.
Greg Utas 19-Nov-21 11:30am View
   
I don't know anything about binance and don't trade cryptos myself. I've only read about them and cannot answer your question in any more detail. As far as private keys are concerned, the exchange must carefully guard its own, or all of the tokens that it owns on behalf of users can get hacked. For the same reason, a user must guard their own private key. There is no way I would trust an exchange that did not give me my private key or allow me to transfer tokens to my own external wallet.
Greg Utas 19-Nov-21 8:08am View
   
Sorry that I couldn't resolve this. I don't have any more suggestions to offer.
Greg Utas 19-Nov-21 6:17am View
   
If this C++ program works, what's the purpose of writing it in Python?

This is probably your assignment. And unfortunately, this site rarely does people's assignments for them.
Greg Utas 19-Nov-21 6:06am View
   
A follow-up question. *Where* does the "undefined reference" error occur? My guess is that it occurs during linking, not compiling. But if there is additional information, such as a file and/or line number, please provide it.
Greg Utas 19-Nov-21 6:02am View
   
Yes, you could use extern, though I don't think it should be necessary. In test.h, you would use "extern" where you had used "static". In test.cpp, you'd use neither.
Greg Utas 16-Nov-21 6:32am View
   
You are talking about a specific type of system design. I was answering generally, because there are many other types of system designs. But even assuming that code uses the same design as your system, I can't think of an easier way to understand it.
Greg Utas 16-Nov-21 6:32am View
   
Deleted
You are talking about a specific type of system design. I was answering generally, because there are many other types of system designs. But even assuming that code uses the same design as your system, I can't think of an easier way to understand it.
Greg Utas 11-Nov-21 16:56pm View
   
"Page 2 of 6" means that anyone who provides code for what has been outlined thus far can expect a request for lots of enhancements.
Greg Utas 29-Oct-21 8:33am View
   
You haven't tried to do anything and have only asked to be given the answers. It is rare for anyone to respond to this type of request, and your post will probably get closed.
Greg Utas 27-Oct-21 9:36am View
   
Yes, but look at the code carefully. The first nested loop indexes arr[0-4][0-3] and the second one indexes arr[0-3][0-4]. One of them is wrong and will access memory that is outside the array.
Greg Utas 25-Oct-21 15:17pm View
   
I think you need to clarify a couple of things:
1. During serial execution, is snippet #1 supposed to finish before snippet #2 runs?
2. You talk about "each program" having 4 threads, but my guess is that you mean one program with 4 threads. Correct?
Greg Utas 22-Oct-21 9:04am View
   
I don't have a lot of experience with this, but he suggested a long long (probably 64 bits). That would reduce the number of collisions given that you're simply hashing on the contents of memory (effectively treating the input object as an array of bytes).

As far as the internals go, you might take bit 0 of the first byte, bit 1 of the second byte, bit 2 of the third byte, and so on. If the size of what you're hashing is less than 64 bytes, you could then wrap around and also take bit 1 of the first byte, bit 2 of the second byte, and so on until you have 64 bits.
Greg Utas 22-Oct-21 8:59am View
   
What are you going to use the hash table for? It's one thing to generate a hash from any type of data, but how are you going to determine the data's type once you find it in the hash table?
Greg Utas 20-Oct-21 8:17am View
   
Member 13566383 kind of has a point. Maybe the bug was in the WriteLine!
Greg Utas 19-Oct-21 19:15pm View
   
I would have answered in much the same way as k5054. Whether a std::map or a sequence of if/else-if statements is faster will greatly depend on the number of strings, their distribution, and the order of the else-if statements.

When you say you assume that the "compiler keeps track of most selected else-if statements", do you mean that it arranges the else-if statements in order of how often they are reached? If so, that couldn't be true in a compiled language, and it's very unlikely in an interpreted language (because if performance was that important, the code would be compiled to start with).
Greg Utas 18-Oct-21 8:16am View
   
They are? Serbian uses the Cyrillic alphabet. :)
Greg Utas 15-Oct-21 10:08am View
   
DŇćitashimashite
Greg Utas 15-Oct-21 8:57am View
   
A vector might be OK, but a list is better if you want to perform insert, erase, or sort operations.

If you only commit ELO changes, each write is independent. You can accumulate pending writes and batch commit them if that helps. Locking the database isn't necessary if only one thread interfaces to it.

Sorting by ELO would be done entirely in memory; there is no need for the external database to be sorted by ELO. When the game starts up, it starts by importing the database.
Greg Utas 12-Oct-21 20:42pm View
   
A Nietszche quote about flyswatters comes to mind. :)
Greg Utas 8-Oct-21 7:50am View
   
Have you looked at the Related Questions on the right of this page? Some of those involve TCP and UDP Hole Punching, and also P2P.
Greg Utas 5-Oct-21 13:58pm View
   
This is far from an assignment for a novice, and you left it until the day it's due? You've got a serious problem, not the least of which is that this isn't a site where people do homework for you.
Greg Utas 2-Oct-21 21:11pm View
   
Further to this answer, volatile prevents the compiler from optimizing out this instruction, even if it actually realizes that it does nothing. And how much time the instruction takes will be specific to the CPU in question, so it's not portable.
Greg Utas 1-Oct-21 18:54pm View
   
Outside the STL, I think you'd find that templates aren't all that common.

The restriction that modules won't help template headers isn't mentioned because it's assumed that you know that a template header can't be pre-compiled. That's not a criticism, because it was a while before I realized this myself. I thought something magical was going on!

However, some compilers likely provide better performance by partially compiling templates. They would have to generate placeholders for template arguments and fill them in when instantiating each template instance.
Greg Utas 29-Sep-21 8:49am View
   
Assuming your code is correct (I've never used this language), what about your firewall? Do you need to enable port 3000?
Greg Utas 25-Sep-21 8:26am View
   
It looks like thread's constructor uses pthread_create but that the compiler can't find pthread_create. I haven't used Linux, so that's all I can tell you. You need to find out where pthread_create is declared and make sure the compiler knows to include its directory when looking for files needed during your build.
Greg Utas 24-Sep-21 7:47am View
   
LOL. I didn't notice that. The question was at the top of the list today, so it must have been the victim of spam that had already been removed.
Greg Utas 24-Sep-21 7:10am View
   
5. It's a long long, so probably in ticks, in which case 0 should be the time of the last system startup and it won't wrap around for a very, very long time.
Greg Utas 30-Aug-21 5:52am View
   
This is my go-to site for C++: https://en.cppreference.com. A wonderful resource.
Greg Utas 29-Aug-21 7:41am View
   
A friend can either be another class or another function, and making it a friend allows it to access all protected and private members.
Greg Utas 27-Aug-21 11:06am View
   
The code shown looks fine, so did you remember to initialize each entry's index?
Greg Utas 16-Aug-21 19:28pm View
   
It is doubtful that you will get help unless you post the details of this secret "pop-up dialog error".
Greg Utas 14-Aug-21 9:52am View
   
Sure, use namespaces. But please stop posting follow-up questions as Solutions. Post them in response to other Solutions.
Greg Utas 12-Aug-21 9:57am View
   
I doubt it'll be debugged after you fixed it. But I gave you a 5.
Greg Utas 12-Aug-21 9:27am View
   
But do you know why your code failed? When you first called the function, n was 3. But what was n when you reached your if(n != 0) line?
Greg Utas 5-Aug-21 18:41pm View
   
You're welcome!
Greg Utas 4-Aug-21 10:12am View
   
If this is an assignment, you should already be familiar with them. Some of them are semaphores, mutexes, atomic operations, and spinlocks.
Greg Utas 4-Aug-21 7:43am View
   
5.
Greg Utas 3-Aug-21 16:17pm View
   
Sort of. If you have T* ptr (a pointer to the type T), the compiler knows how many bytes an instance of T occupies, so it generates code to add that number of bytes to ptr when it sees the expression ptr++. C++ also has an operator called sizeof that will tell you the size of a type. So, another way to write ptr++ would be ptr += sizeof(T). In this case, T is an int.
Greg Utas 3-Aug-21 16:12pm View
   
It is incremented every time through the loop. So the third time, it points to item 2, and so on.
Greg Utas 2-Aug-21 8:22am View
   
I don't think using CLR should make the code less debuggable. Note that this link (https://docs.microsoft.com/en-us/cpp/build/reference/eh-exception-handling-model?view=msvc-160) says that /EHa (to also catch Windows structured exceptions) is mandatory when using CLR. Scroll down to "Exception handling under /clr".
Greg Utas 1-Aug-21 10:18am View
   
If negative numbers are allowed, it might be the two smallest numbers. :)
Greg Utas 31-Jul-21 10:12am View
   
No wonder you couldn't. I probably couldn't either, because the requirements are very poorly worded.
Greg Utas 31-Jul-21 10:09am View
   
LOL
Greg Utas 27-Jul-21 18:21pm View
   
Good point, so I told OP about it in a comment above.
Greg Utas 27-Jul-21 18:19pm View
   
Also see the comment below my post.
Greg Utas 26-Jul-21 13:48pm View
   
5. LOL. Totally missed that. If that's only bug, it's a howler.
Greg Utas 25-Jul-21 12:59pm View
   
In explaining extern, https://en.cppreference.com/w/cpp/language/storage_duration says, "In addition, a variable *declaration* that uses extern and has no initializer is not a definition."

Even

class Foo;

is a (forward) declaration which says that Foo is a class. The definition will be elsewhere.

Here, the extern says that gpub is a pointer to a Pub. That's a data declaration, no different than

in a .h: extern const char* const WHILE_STR;
in a .cpp: const char* const WHILE_STRING = "while";
Greg Utas 25-Jul-21 10:12am View
   
Yes, I get that there will be a linker error if the extern item isn't defined somewhere.

Then you say "supposed to provide the actual declaration"--I assume you mean "definition" here, to resolve the extern. In which case the library creates something and makes it available via the extern. Which brings me back to my original point, that whether the extern item is a singleton or not, it's not good code.
Greg Utas 25-Jul-21 9:08am View
   
If the last line that you're referring to is

static Pub_init pub_init; //file scope

then this simply creates an instance of Pub_init when the program starts up.

Pub_init has a global, init_count. I'm guessing that Pub's constructor invokes Pub_init to track of the number of Pub instances. If so, that's not how I'd do it. I'd just declare init_count as static at file scope in the .cpp and have Pub's constructor and destructor increment and decrement it. Having a separate Pub_init class adds no value unless it's doing a fair bit more.
Greg Utas 25-Jul-21 8:08am View
   
So there could be a library that defines the class Pub, but the user of the library is expected to create an instance (gpub) that the library can access? That still leaves a lot unexplained.
Greg Utas 24-Jul-21 20:49pm View
   
You're welcome! C++ has many good and bad practices, partly because it evolved from C, and I'm still learning myself. It's interesting to see someone else running the same gauntlet. :)
Greg Utas 20-Jul-21 6:38am View
   
Thanks!
Greg Utas 19-Jul-21 13:39pm View
   
Despite some idiot's downvote, this is a possible explanation.
Greg Utas 18-Jul-21 9:29am View
   
You haven't tried anything yet. And you didn't even specify the language that this is supposed to be coded in. But no one here will write all the code for you anyway. This is not a site for getting your homework done, only for helping those who have done some work and have questions.
Greg Utas 18-Jul-21 7:08am View
   
A scope resolution operator can't check if a number is positive or negative, but it could be used to invoke a function in another namespace that does check the number.
Greg Utas 16-Jul-21 11:01am View
   
Sorry, can't help you. I write C++ and am not familiar with what you're using.
Greg Utas 16-Jul-21 11:01am View
   
Deleted
Sorry, can't help you. I write C++ and am not familiar with what you're using.
Greg Utas 16-Jul-21 8:38am View
   
Single-threaded? I'm curious. What happens when the thread blocks on disk I/O, for example? Or is there a thread pool for that, which you're excluding from the main thread?
Greg Utas 15-Jul-21 13:22pm View
   
You are probably changing it so that you won't get caught. Begone!