Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: November 21, 2024, 5:16 am

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom error message for stack overflow in C++
#21
RE: Custom error message for stack overflow in C++
(August 12, 2021 at 10:34 am)FlatAssembler Wrote: Well, I think I am competent enough to have a job. And even if I am not, I don't think university will make me competent. They did not teach me how to change a lightbulb in our electrical engineering classes, so they also will not teach me useful things in our programming classes.

I think you will struggle to get high pay without a degree, (or even your first job), but who knows.

As a test of this competence, lets see if you can fix your project.  The first thing that I've mentioned is to go through all your methods where const class parameters are being passed by copy, and change them to pass by reference.  Google it if you don't understand it.

If this were going to be part of your "portfolio" for showing people that you can code, it also has a structural problem.  Everything is a .cpp file, instead of the standard .h (or .hpp) file for the class declarations, and .cpp files for the class implementation.  Yes, having two separate files is a pain for maintenance, but there is a reason for it, related to compiling and linking.  You say you have problems with statics?  Yes, they are a pain, but they need to be declared in a .h (or .hpp) file, and actually implemented in the .cpp
Reply
#22
RE: Custom error message for stack overflow in C++
(August 12, 2021 at 10:34 am)FlatAssembler Wrote: Well, I think I am competent enough to have a job. And even if I am not, I don't think university will make me competent. They did not teach me how to change a lightbulb in our electrical engineering classes, so they also will not teach me useful things in our programming classes.

College isn't about making people competent; it's about educating you in a field of knowledge so that you at least know something before you go to work and find out you really know very little.  You will learn more in the first year at a good job than 4 years of university.  However, in a lot of fields, you won't ever get that chance if you don't have a degree.  That's just how it is.

Electrical Engineering isn't building maintenance.  If you learned basic electrical theory (Ohms law and such) and enough digital logic to write programs, then you did learn useful knowledge.  You could learn those things on your own as well, but its more difficult to convince a potential employer that you have knowledge.  And few people have the drive and intellect to educate themselves in difficult fields of study.  If you plan to be an entrepreneur and build something entirely new and creative, then a diploma is just a piece of paper, but without the basic knowledge you just won't get very far unless you have a very high intellect and some original ideas.
Why is it so?
~Julius Sumner Miller
Reply
#23
RE: Custom error message for stack overflow in C++
(August 11, 2021 at 9:14 pm)Abaddon_ire Wrote: Flat is seeking those gullible to do his homework again.

Nope.

I had a grad student who spent so much time bugging people on forums to solve his problems that he never learned to think for himself.  He would blame them for why his stuff didn't work.
Reply
#24
RE: Custom error message for stack overflow in C++
(August 13, 2021 at 10:27 am)HappySkeptic Wrote:
(August 12, 2021 at 10:34 am)FlatAssembler Wrote: Well, I think I am competent enough to have a job. And even if I am not, I don't think university will make me competent. They did not teach me how to change a lightbulb in our electrical engineering classes, so they also will not teach me useful things in our programming classes.

I think you will struggle to get high pay without a degree, (or even your first job), but who knows.

As a test of this competence, lets see if you can fix your project.  The first thing that I've mentioned is to go through all your methods where const class parameters are being passed by copy, and change them to pass by reference.  Google it if you don't understand it.

If this were going to be part of your "portfolio" for showing people that you can code, it also has a structural problem.  Everything is a .cpp file, instead of the standard .h (or .hpp) file for the class declarations, and .cpp files for the class implementation.  Yes, having two separate files is a pain for maintenance, but there is a reason for it, related to compiling and linking.  You say you have problems with statics?  Yes, they are a pain, but they need to be declared in a .h (or .hpp) file, and actually implemented in the .cpp

OK, I have decided to try it and I have changed some fields to be static and passed some parameters by reference. Now it works in CLANG, but it still does not work in Visual Studio.
Reply
#25
RE: Custom error message for stack overflow in C++
The pass-by-reference changes look good.

Changing some data to static in TreeNode does solve some memory-use problems, but you have another potential problem. You are still initializing the data in the constructor of TreeNode, every time. This is wasteful, and rather nasty looking.

If you use static data, you need to find a way of initializing it only once. A non-thread-safe way would be to have another static int initializedStatics; Set it to false initially, and then your constructors can have an

if (! initializedStatics) {
... do initialization work
initializedStatics = true;
}

Note that this is a bad pattern, as it isn't thread-safe. It would be better to batch all the statics into a singleton, and initialize the singleton using some sort of thread lock (these are different in Windows and Linux, so it is a pain to program them cross-platform). However, your program isn't multi-threaded anyway.

I mentioned earlier about the separate .h (for class declarations) and .cpp files (for class method implementations and static variable implementation).

What you have done in TreeNode.cpp, with your static changes will work, but ONLY because everything is compiled into one link module (i.e. one program, not multiple libraries that bring in the TreeNode.cpp file). If multiple libraries were to import TreeNode.cpp (you should import .h or .hpp files, not the .cpp), there would be multiple implementations of the static variables, causing either a program link error (or if it links, could blow-up at runtime if not all versions are initialized). It may not affect your program, but it does look bad to a prospective employer if they were to see this code.

As for getting Windows to work, go into Visual Studio, and increase the reserve heap size in the link parameters. Sure, this is a pain if you are trying to build from CMake, as you would have to insert the parameter /HEAP:8388608,4096 to make an 8MB heap, for instance. It is possible to add parameters in CMake only for MSVC, but I'm not an expert. In Visual Studio, changing the Reserve Heap size in the link is just something in the GUI. Just make it 8388608 . If it still doesn't work, break on any runtime exceptions, and look at your program stack to find if you have an endless loop.
Reply
#26
RE: Custom error message for stack overflow in C++
(August 13, 2021 at 10:27 am)HappySkeptic Wrote: I think you will struggle to get high pay without a degree, (or even your first job), but who knows.

I have experience I this regard - I do not have a degree, but I make very good money in software engineering. If I had to go back and do it again, I'd get the degree.
Reply
#27
RE: Custom error message for stack overflow in C++
(August 19, 2021 at 7:43 pm)Jackalope Wrote:
(August 13, 2021 at 10:27 am)HappySkeptic Wrote: I think you will struggle to get high pay without a degree, (or even your first job), but who knows.

I have experience I this regard - I do not have a degree, but I make very good money in software engineering. If I had to go back and do it again, I'd get the degree.

I have a BS in Computer Science; I now fix cash registers for a living. My advice -- keep working, whatever you do!
Reply
#28
RE: Custom error message for stack overflow in C++
And I mean, fix some cash registers.  (nervously adjust tie)

Boy I tell ya, it's tough out there when all you know is what you tell yourself and free advise comes at a price.
Reply
#29
RE: Custom error message for stack overflow in C++
(August 20, 2021 at 12:09 am)Ranjr Wrote: And I mean, fix some cash registers.  (nervously adjust tie)

Boy I tell ya, it's tough out there when all you know is what you tell yourself and free advise comes at a price.

It's always easier to to learn shit the hard way, so it would seem.
Reply
#30
RE: Custom error message for stack overflow in C++
(August 20, 2021 at 12:42 am)Jackalope Wrote: It's always easier to to learn shit the hard way, so it would seem.

I tried the easy way but it was too fucking hard.
Reply



Possibly Related Threads...
Thread Author Replies Views Last Post
  What is the most absurd error message a program you have made was outputting? FlatAssembler 38 6087 June 14, 2023 at 8:01 am
Last Post: FlatAssembler
  Error 502 bad gateway for Rational Responders Brian37 13 1695 April 23, 2022 at 4:17 pm
Last Post: BrianSoddingBoru4
  How Do I Send an SMS message From UK mobile to a US one ReptilianPeon 11 2165 July 9, 2018 at 5:17 pm
Last Post: bennyboy
  HELPPPPP Blue screen error just now!!! Edwardo Piet 114 12951 November 10, 2015 at 2:26 am
Last Post: Aractus
  Disk read error. Creed of Heresy 12 4369 July 27, 2012 at 9:19 am
Last Post: Tiberius
  Video Error: Grey circle with a white exclaimation mark inside. Reforged 5 4043 July 5, 2012 at 1:19 am
Last Post: Reforged



Users browsing this thread: 1 Guest(s)