|
schnarf posted:Issues that only appear when optimization is on usually mean a bug in your code that didn't manifest itself without optimizations. For example, in this fragment of code: Yeah, I'm aware of that. But I don't think that's the issue because I can literally compile this code code:
Output on my machine without optimization: hello world Output on my machine with optimization: hello world Output on server without optimization: hello world Output on server with optimization: 500 internal server error
|
# ? Jun 16, 2012 17:57 |
|
|
# ? Jun 8, 2024 07:03 |
|
Have you tried it running manually instead of through CGI?
|
# ? Jun 16, 2012 17:58 |
|
And have you tried static linkage? It's not a great solution but it's often a good diagnostic step.
|
# ? Jun 16, 2012 18:04 |
|
Thanks for the suggestions, guys.Vanadium posted:Have you tried it running manually instead of through CGI? roomforthetuna posted:And have you tried static linkage? It's not a great solution but it's often a good diagnostic step. seiken fucked around with this message at 22:19 on Jun 16, 2012 |
# ? Jun 16, 2012 22:07 |
|
Did the server logs say anything? 500 errors usually have something meaningful there
|
# ? Jun 17, 2012 01:56 |
|
Nothing relevant (just logged the fact that it couldn't find a customised 500 error page because I haven't made one).
|
# ? Jun 17, 2012 03:22 |
|
Try running the program directly instead of through the web server and see if you get any useful output. Also, use ldd to verify any shared library dependencies are being found. e: Also, if you're doing anything with threads, some race conditions don't manifest in debug builds. The number of processors can also affect how these bugs manifest. It's not likely, especially if it's failing 100% of the time, but I've run into similar bugs before. Paniolo fucked around with this message at 06:16 on Jun 17, 2012 |
# ? Jun 17, 2012 05:44 |
|
If its apache set the loglevel to debug Also see if it is running chroot'ed or with less privileges, though why that would be affected by optimization I could not say. If static linking works it could well be something to do with access or the environment of the web server process.
|
# ? Jun 17, 2012 06:29 |
|
Why am I getting a warning saying my member functions aren't initialized?code:
|
# ? Jun 18, 2012 21:59 |
enthe0s posted:Why am I getting a warning saying my member functions aren't initialized? Well do you have any other fields in the class?
|
|
# ? Jun 18, 2012 22:04 |
|
nielsm posted:Well do you have any other fields in the class? Those are my only two variables. However, I do have an empty constructor. Do I also have to initialize it for that?
|
# ? Jun 18, 2012 22:10 |
|
x(x) doesn't do what you think it does.
|
# ? Jun 18, 2012 22:23 |
|
yes it does
|
# ? Jun 18, 2012 22:28 |
|
enthe0s posted:Why am I getting a warning saying my member functions aren't initialized? Come again? You mean your member variables?
|
# ? Jun 18, 2012 22:32 |
|
enthe0s posted:Those are my only two variables. However, I do have an empty constructor. Do I also have to initialize it for that?
|
# ? Jun 18, 2012 22:38 |
|
Plorkyeran posted:Yes, you need to initialize your variables in all of the constructors. Can't wait for delegating constructors. Unfortunately I use Visual Studio a lot and based on their C++11 feature set for VS2k12 I'll be waiting for another 20 years.
|
# ? Jun 18, 2012 22:43 |
|
xgalaxy posted:Come again? Yeah sorry, that's what I meant to say. Plorkyeran posted:Yes, you need to initialize your variables in all of the constructors. Do I do this the same way as I did my other constructor? e: Yes you do. Thanks everyone. enthe0s fucked around with this message at 23:16 on Jun 18, 2012 |
# ? Jun 18, 2012 22:48 |
|
Part of my assignment this week involves calcuating the sum of a series of consecutive even numbers using a formula, iterative and recursive methods. I got it all done, but I wonder if there isn't a more efficient way to do the recursive method. Here is the function I came up with code:
|
# ? Jun 19, 2012 01:38 |
|
Apart from recursion being a bad solution to that problem because it's begging for a stack overflow, which can be ignored since it's a programming test, you could make it more efficient by having two functions - the first one is the one the "user" would call, and would do the validation of the input, then the second one would do the recursion and everything else. That way you wouldn't keep doing "if (n%2 == 1)" every time round the loop, since after the first time you know for certain that that's not going to be true. Edit: Also you're declaring evenSum and not using it at all.
|
# ? Jun 19, 2012 01:43 |
|
roomforthetuna posted:Apart from recursion being a bad solution to that problem because it's begging for a stack overflow, which can be ignored since it's a programming test, you could make it more efficient by having two functions - the first one is the one the "user" would call, and would do the validation of the input, then the second one would do the recursion and everything else. That way you wouldn't keep doing "if (n%2 == 1)" every time round the loop, since after the first time you know for certain that that's not going to be true. I didn't catch evenSum, thanks. The program is 4 functions in total, the first verifies that the input is a non negative integer. The second finds the sum of the series using the formula, the third function uses iteration and the final uses recursion. This is the first time I've used recursion and it felt a little clunky.
|
# ? Jun 19, 2012 02:19 |
|
It's feels clunky because every test I've seen asks you to do recursion when it really doesn't make any sense. I've seen very very few real world problems where recursion would have been a better idea than a simple loop. But that is probably why every test has some stupid contrived problem where they want you to utilize recursion. I guess they have to teach it somehow.
|
# ? Jun 19, 2012 02:27 |
|
xgalaxy posted:I've seen very very few real world problems where recursion would have been a better idea than a simple loop. Saying things like this is usually a pretty good indicator that you don't grok the thing you're criticizing.
|
# ? Jun 19, 2012 03:11 |
|
Captain James T. Kirk, USS Enterprise-D posted:What's a tree?
|
# ? Jun 19, 2012 03:43 |
|
Nippashish posted:Saying things like this is usually a pretty good indicator that you don't grok the thing you're criticizing. Personal attacks sure do raise the level of good discussion and debate. I didn't say recursion is bad. I didn't say you should never use recursion. I simply stated that I've seen or had to personally / professionally deal with very few real world problems where recursion would have been a better solution. But if attacking me makes you feel superior than whatever. Fire away.
|
# ? Jun 19, 2012 03:54 |
|
A standard problem solved by recursion is a depth-first search of a tree.C++ code:
|
# ? Jun 19, 2012 04:02 |
|
Suspicious Dish posted:A standard problem solved by recursion is a depth-first search of a tree. This just helps to prove my point. I never said that there are no situations where recursion is better. I said there are few. I'm staring right now at a complex code base sitting at well over 500k lines of code. I can count on one hand how many times recursion is used. Granted its a large code base and I may be missing a few places. But I think it speaks volumes that I can pretty much guess where it may be used in the code base and where it wouldn't be.
|
# ? Jun 19, 2012 04:18 |
|
xgalaxy posted:Personal attacks sure do raise the level of good discussion and debate. Be careful of what you say around here or your tail might get called out.
|
# ? Jun 19, 2012 05:38 |
|
It does seem silly to teach recursion through making people write a terrible function that they should never write, rather than trying to come up with the simplest possible situation in which recursion is actually a good solution and teaching it with that. It's like they're teaching "there are several ways to do things but this one is stupid" rather than "there are several ways to do things and sometimes this one is appropriate".
|
# ? Jun 19, 2012 06:02 |
|
There are domains that are naturally recursive and there are domains that aren't. As a compiler writer, most of the data I deal with is recursively defined and acyclic, so recursion is ideal. When I worked on object databases, it was mostly highly cyclic graphs, so recursion was less ideal. I wrote a configuration file parser once — that was technically XML, but most walks over it were fixed-path, so recursion was really just not relevant for clients. I was also a TA once, and let me assure you, the annoyance of occasionally needing to convince students to get over the artificial setup and just focus on wrapping their heads around the underlying concepts was vastly outweighed by not having to spend thirty minutes developing, explaining, and justifying a more realistic problem statement.
|
# ? Jun 19, 2012 07:19 |
|
Yeah, as interesting as "code me up a parser for this DSL" is as a question, it's pretty complex as an "introduction to recursion" problem. So then we get artificial stuff like "do an in-order traversal of this tree".
|
# ? Jun 19, 2012 08:05 |
|
Jabor posted:Yeah, as interesting as "code me up a parser for this DSL" is as a question, it's pretty complex as an "introduction to recursion" problem. I honestly saw recursion as a toy until I stumbled across dynamic programming - which is basically recursion except you store the solutions to sub-problems in a data structure instead of recomputing them every single time. DP will produce a solution about as fast and space efficient and understandable as you can get for some kinds of problems, but good luck explaining how your code works to a front-end developer or a manager.
|
# ? Jun 19, 2012 12:03 |
|
hieronymus posted:I honestly saw recursion as a toy until I stumbled across dynamic programming - which is basically recursion except you store the solutions to sub-problems in a data structure instead of recomputing them every single time. DP will produce a solution about as fast and space efficient and understandable as you can get for some kinds of problems, but good luck explaining how your code works to a front-end developer or a manager. Well that's the thing. Proofs of dynamic programming are really simple, they just have a step in them that looks like magic. Just introduce that step as 'trivial' and nobody will ask any questions. The emperor is wearing a fine robe!
|
# ? Jun 19, 2012 13:09 |
|
Jabor posted:Yeah, as interesting as "code me up a parser for this DSL" is as a question, it's pretty complex as an "introduction to recursion" problem. What I was griping about is "use recursion to calculate a factorial" or "use recursion to calculate a sum of numbers" - both tasks for which recursion is poorly suited, which make the lesson teach, as a side-effect, "recursion is stupid and worse than iteration in every way". I think it's important to teach people to recognize when recursion is a good solution, at the same time as teaching them how to do it. If you don't do that then it seems like recursion is nothing but an artificial constraint you might impose on yourself to show off. (Is "dynamic programming" what I would have been using for a chess AI?)
|
# ? Jun 19, 2012 14:57 |
|
roomforthetuna posted:That's not what I was griping about - artificial stuff like a traversal of a tree is a fine thing to teach recursion, because if you want to traverse a tree, recursion is pretty good for that. It doesn't matter that the situation is artificial - all early programming lesson situations will be, you're not going to be solving actual unsolved problems. I can see DP being used for a chess API - take a look at http://people.csail.mit.edu/bdean/6.046/dp/. If the problem you're trying to solve looks like one of these problems, it's time to whip out dynamic programming - I can see why DP gets skipped over for most undergrad programs because coming up with a novel DP solution is something that I would not expect most people to be able to do.
|
# ? Jun 19, 2012 15:15 |
|
Fibonacci is a good intro-to-dynamic-programming example that is recursively defined, easy to analyze, and and easy to compare against a recursive solution. You don't even need to teach the undergrads about all those stack frames you are saving - just expand the recurrence a few times to show the redundant work. You can even bring up the topic of whether or not the entire solutions space needs to be stored. WRT tree traversal, using the stack as a glorified bookmark into a data structure can get expensive. Isn't it funny that Russell & Norvig's generalized tree algorithms do everything with a queue and a loop? If your problem doesn't use all that recursive context then why keep it around? But enough algorithms chat, this is the C/C++ thread!
|
# ? Jun 19, 2012 17:34 |
|
Is there some kind of Boost.Multibimap? e: Let me get a little more specific. I have a bunch of binary relationships (let's call them "connections") between Foos, and I need to look up, given some Foo, which Foos are connected to it. I could make a graph, but it would be pretty sparse. edit 2: I realized that I need a more sophisticated structure and found Boost.MultiIndex, so I'm going with that. raminasi fucked around with this message at 21:48 on Jun 19, 2012 |
# ? Jun 19, 2012 19:12 |
|
So I want to convert a hex value into a decimal value while I'm outputting to a stream. However, it seems as though I can only change a stream to hex mode at the beginning? This would be fine if I were just outputting a single value, but I also have other things I want to output in the same stream. For reference, this is what I'm currently doing:code:
code:
|
# ? Jun 19, 2012 22:59 |
|
enthe0s posted:And I want to output customer.id (given to me as a hex string) and convert it to a dec string. From what I've seen (correct me if I'm wrong), you can only change the value if you change the beginning of a stream like so:
|
# ? Jun 19, 2012 23:08 |
|
Isilkor posted:You can stream in the stream modifiers whenever you want: http://codepad.org/KQ0u3PES I've tried that and it doesn't seem to affect the output at all. Does hex not work on strings?
|
# ? Jun 19, 2012 23:59 |
|
|
# ? Jun 8, 2024 07:03 |
|
It sounds like what you're wanting to do is convert the string to a number, and then output that number as hexadecimal, right?
|
# ? Jun 20, 2012 00:03 |