|
Asking for assistance - Anyone with c+ & robotics feel like earning karma? Daughter works with underfunded school in rural area; somehow they have robot lab and robot arm controlled by c+. They have some questions, I haven't thought about c at all for 19 years since programming 101, and I am not a coder in any event. I don't have details- will put you in touch with teacher/instructor. I'll do someing nice, write you a song or something if you can make a difference. If it matters, daughter is on SA. chughes2002 at gmail if need to contact Apologies if inappropriate or wrong thread. some_admin fucked around with this message at 23:15 on Oct 27, 2012 |
# ? Oct 27, 2012 23:11 |
|
|
# ? Jun 8, 2024 06:03 |
|
Post a new thread with the questions? Plenty of people are likely to help out. Robots are cool after all.
|
# ? Oct 28, 2012 00:28 |
|
I'm reviewing a practice exam for my Op Sys class, and I am having trouble answering some of the questions. They all concern semaphores, and I need to make sure I understand them. The first one concerns the canonical Dining Philosophers problem (code): Given the test method... code:
code:
Edit: Also (for a different problem), what's the easiest way to measure the amount of system time that has elapsed during a given segment of code? Hot Yellow KoolAid fucked around with this message at 03:17 on Oct 28, 2012 |
# ? Oct 28, 2012 03:10 |
|
Hot Yellow KoolAid posted:I'm reviewing a practice exam for my Op Sys class, and I am having trouble answering some of the questions. They all concern semaphores, and I need to make sure I understand them. I'm assuming that you mean the 'put_fork' method(since you quoted that part)? If so, then the left and right philosophers will both try to eat if they are hungry. If so, they will fail, because the philosopher in question hasn't put down his forks yet.
|
# ? Oct 28, 2012 16:37 |
|
Have any of you found a cross-platform library for generating exceptions that include a stack trace? I see OS-specific methods of acquiring the call stack to put in a custom exception class, but I wonder if anybody ever went the extra mile and made a library for it. One thing I do wish I could have in C++ is a nice stack trace.
|
# ? Oct 29, 2012 06:02 |
|
All right, at my wit's end here. Working on an assignment where I'm to take a previous assignment, and implement it with ADT's (classes). Most of the files have already been converted, leaving one header and one cpp file for me to do. However, I'm hitting some errors that I have no idea how to deal with, so any information would be hugely appreciated. game.cpp and game.h (the only two I'm allowed to modify) http://pastebin.com/sut4yYTL http://pastebin.com/sdYRwEYY The rest of the files. http://pastebin.com/jDEG8Jpn http://pastebin.com/5HuSpAv2 http://pastebin.com/Qg1WJscd http://pastebin.com/hGwvm15h http://pastebin.com/N1e8M06E The error I'm getting: code:
|
# ? Oct 29, 2012 07:39 |
|
Your game.cpp and game.h files are the same on pastebin (guessing you pasted the wrong thing).
|
# ? Oct 29, 2012 07:50 |
|
The Gripper posted:Your game.cpp and game.h files are the same on pastebin (guessing you pasted the wrong thing). Fixed. 2:30 am does not agree with me.
|
# ? Oct 29, 2012 07:56 |
|
Few things wrong, nothing super serious though. In game.h you should just be #including provider.h and guesser.h rather than using forward declaration (see: http://stackoverflow.com/questions/553682/when-to-use-forward-declaration). That will sort out your incomplete type errors. After that you'll need to use an initialization list for Game::Game in game.cpp to initialize your guesser (because there is no default constructor, see: http://www.cprogramming.com/tutorial/initialization-lists-c++.html). That's as easy as changing line 11 to: code:
That should get you on your way! e: there was something else in Game::guessHasBeenMade as well (not calling getResponseToGuess on the instance of Provider you're creating) but that should be pretty easy to fix once the errors you're already getting are resolved. The Gripper fucked around with this message at 08:56 on Oct 29, 2012 |
# ? Oct 29, 2012 08:40 |
|
Never mind, me being dumb here. Thanks for the info! The Gripper posted:e: there was something else in Game::guessHasBeenMade as well (not calling getResponseToGuess on the instance of Provider you're creating) but that should be pretty easy to fix once the errors you're already getting are resolved. Yeah, caught that, and the characterIs/IsNotInWord functions are a part of the Guesser class, caught that too. Now everything's working, other than when the computer guesses a correct letter, it then repeats that letter again. Just gotta figure that out. e: Nope. Well, actually, yeah, it doesn't seem to be reading the wordlist at all. Hmm. Okay, it is reading the wordlist, but something is hosed up with the characterIsInWord function, I think. And if I run it's guesses out and type in the word (which I've verified is on the list), it says it doesn't know that word. Gotta sleep. If someone sees what's causing the wordlist to get hosed or whatever, please point me in the right direction. And thanks again for the help, Gripper. Link to the current files: https://dl.dropbox.com/u/11481768/Hangman%20ADT.zip Lprsti99 fucked around with this message at 09:57 on Oct 29, 2012 |
# ? Oct 29, 2012 08:51 |
|
Quote is not edit
|
# ? Oct 29, 2012 09:49 |
|
It's just that you're passing a copy of your guesser in getGuesser() (and I suppose getProvider too, though I don't think your provider does anything that would make that a problem..) so changes to charactersTried[] are being discarded. You could either change your Guesser and Provider class members to be pointers, and getGuesser and getProvider to return pointers (will require you to change game.cpp and hangman.cpp to use pointer dereference -> instead of . for calls), or change Guesser and Provider to references outright. I don't know which of those people here would suggest, though I think in general pointers are preferred for reasons that aren't particularly applicable in this assignment. If hangman.cpp is a file that was provided to you in the state it's in now then the second (reference) option is the solution, given it's not using any pointer dereferencing.
|
# ? Oct 29, 2012 11:32 |
|
The Gripper posted:It's just that you're passing a copy of your guesser in getGuesser() (and I suppose getProvider too, though I don't think your provider does anything that would make that a problem..) so changes to charactersTried[] are being discarded. That did it, and it works perfectly now. Thank you so very much.
|
# ? Oct 29, 2012 15:44 |
|
rjmccall posted:The first question is whether you really need separate Point2 and Point3 templates instead of, say, a Point template with a dimension argument. Even if the types are significantly different for different dimensions, making them partial specializations of the same template makes a lot of the type relationships trivial to compute. In C++11, you can even make template aliases for things like Line2 and Point3. I just tried implementing this, and Visual Studio 2010 isn't happy with even this: C++ code:
code:
|
# ? Oct 29, 2012 20:25 |
|
GrumpyDoctor posted:I just tried implementing this, and Visual Studio 2010 isn't happy with even this: No you're using visual studio 2010, which is like 10 years behind the rest of the world in terms of supporting the C++ spec.
|
# ? Oct 29, 2012 21:34 |
|
GrumpyDoctor posted:I'm assuming your code is on the cutting edge of template specialization wizardry and outsmarted my compiler. It's entirely possible. Do note that the "database" needs to come before line_for_point (or you at least have to forward-declare line_template_for_point_template), despite me confusingly presenting it the other way around.
|
# ? Oct 29, 2012 23:08 |
|
Maybe this is a bit of a noobie question, but which of these is preferable?code:
|
# ? Oct 30, 2012 03:21 |
|
oRenj9 posted:Maybe this is a bit of a noobie question, but which of these is preferable? It's personal preference, and in C++, they're equivalent (which means use type B). There's also a third option, which allows you to use use both struct foobar_c and foobar_c to refer to the struct: code:
|
# ? Oct 30, 2012 03:32 |
|
Note that some compilers may barf on that last one. I typically use:C++ code:
|
# ? Oct 30, 2012 03:34 |
|
Suspicious Dish posted:Note that some compilers may barf on that last one. Not that I'm doubting you, but what terrible compilers are you using that still barf on that?
|
# ? Oct 30, 2012 07:19 |
|
rjmccall posted:Not that I'm doubting you, but what terrible compilers are you using that still barf on that? SunPro
|
# ? Oct 30, 2012 15:25 |
|
Any hints as to what math functions are particularly expensive? Despite SSE intrinsics and such? I just managed to cut the runtime of my oscillator to 45% of the original by replacing a single pow(2,x) with a lookup table based replacement function. Which is surprising how that one function can make such an impact, considering it's the only 5% that isn't additions and multiplications.
|
# ? Oct 30, 2012 21:07 |
|
pow is pretty much always insanely expensive. pow(2,x) is completely unnecessary anyway since you can just insert the exponent directly into the bits of the floating point number. In fact any time that you are doing pow(C,x) with constant C, you can replace it with exp(x * log(C)) where log(C) is precomputed for a much cheaper evaluation. Chances are that pow is implemented with some combination of exp and log anyway, but computed in higher precision so it'll be even more expensive.code:
|
# ? Oct 30, 2012 21:29 |
|
Power, trig functions, sqrt. Anything that has to be iterated. You should be wary of math stuff that is more complicated than basic arithmetic and bit-shifting.
|
# ? Oct 30, 2012 21:30 |
|
taqueso posted:Power, trig functions, sqrt. Anything that has to be iterated. You should be wary of math stuff that is more complicated than basic arithmetic and bit-shifting. Most trig functions are reasonably cheap on recent x86 (I did a project about a year and a half ago that involved writing fast approximations; the tradeoffs were painful). Also, for the special but useful case of inverse sqrt, there is an SSE intrinsic based on a hardware LUT that costs like 2 cycles (you should never do the Numeric Recipes/quake 3 inverse sqrt routine ).
|
# ? Oct 30, 2012 22:12 |
|
quote:pow(2,x) is completely unnecessary anyway since you can just insert the exponent directly into the bits of the floating point number. Forgot to mention, the exponents are floating point and can be negative. Combat Pretzel fucked around with this message at 06:09 on Oct 31, 2012 |
# ? Oct 31, 2012 06:07 |
|
Volte posted:
This is undefined behavior. (Use a union.)
|
# ? Oct 31, 2012 06:49 |
|
floWenoL posted:This is undefined behavior. What exactly does that function return...? I'm not familiar with the syntax used there in the return statement. Like, why are there parentheses and 2 asterisks.
|
# ? Oct 31, 2012 06:52 |
|
Don't worry about it for now. You'll get around it to eventually.
|
# ? Oct 31, 2012 07:11 |
|
an skeleton posted:What exactly does that function return...? I'm not familiar with the syntax used there in the return statement. Like, why are there parentheses and 2 asterisks. The stuff in parentheses is casting to float *. (It's also the wrong way to do that thing)
|
# ? Oct 31, 2012 07:11 |
|
Just realized I may have been unclear. I know what a pointer is and that * is used to make a pointer, but not sure why there was double * and a &. Anyways, thanks, googling "casting" now
|
# ? Oct 31, 2012 07:19 |
|
If it makes you feel any better I know what pointers, casts and references are and still have no clue what it's supposed to be doing since I don't know the math behind it.
|
# ? Oct 31, 2012 07:25 |
|
an skeleton posted:I know what a pointer is and that * is used to make a pointer Not quite. There's two different uses of *, there. One is part of a type declaration, like float *a, and the other is known as the dereference operator. In C (C++ is kind of mean and silly about this with references), type syntax dictates usage. If I have an int i, &i will give me a pointer pointing to i. The type of that is a pointer: int *p = &i. I can get the value back with the * operator: *p. Casting is an override mechanism. The compiler will note that the variable is one type, and you say "oh compiler, I'm smarter than you. The type of this variable is actually this". If you cast an integer to a float, there's actually a special rule mandated by C that says that you have to convert it to the appropriate float representation, so (float)3 will give you back a float that represents 3.0 as close as it can possibly can. Note that the bytes that make up these two values are completely different: one is simply 00 00 00 03, and the other is some [url=http://en.wikipedia.org/wiki/IEEE_floating_point]fancy weird version of binary scientific notation[/fixed] where you have a decimal part and then an exponent. What Volte is trying to do is trick the compiler into using the raw bytes of the integer into the appropriate floating point number. Technically, that's undefined by the C standard, but every compiler and platform will work with it anyway, so it's a common trick. I don't know why.
|
# ? Oct 31, 2012 07:29 |
|
Suspicious Dish posted:Not quite. There's two different uses of *, there. One is part of a type declaration, like float *a, and the other is known as the dereference operator. In C (C++ is kind of mean and silly about this with references), type syntax dictates usage. So the first * is a type declaration and the second one (in the parentheses) is the dereference operator, which casts?
|
# ? Oct 31, 2012 07:32 |
|
Other way around. e; the being in brackets part is what makes it cast, not the *, to clarify. (float)6 will cast the integer 6 to a float 6.0000.... The Gripper fucked around with this message at 07:38 on Oct 31, 2012 |
# ? Oct 31, 2012 07:33 |
|
an skeleton posted:So the first * is a type declaration and the second one (in the parentheses) is the dereference operator, which casts? The first one is the dereference operator. Let's take this one step at a time. Given an int foo: &foo - Make a pointer to the integer, so the type of this value is int * (float *)&foo - Take the int * we got, and cast it into a float * *(float *)&foo - Dereference the float *, giving us a float with the same byte pattern as foo, according to every real-world compiler out there. According to C, the cast from int * to float * is undefined, meaning it could make a program which writes a funny knock knock joke to stdout, it could call the Mayans and tell them to blow up the world, or anything else it wants to.
|
# ? Oct 31, 2012 07:46 |
|
The correct way to "reinterpret" the integer bits as a float is to use a union - which instead of being undefined behavior is merely implementation defined.
|
# ? Oct 31, 2012 07:49 |
|
Ahhh, I see. So the dereferencer is like a trick to make it work? I'm not certain what giving it the same "byte pattern" means.
|
# ? Oct 31, 2012 07:51 |
|
It's probably best to not try and learn about dereferencing and casting from that example since it exists only to do something you're probably not going to ever want to do.
|
# ? Oct 31, 2012 08:01 |
|
|
# ? Jun 8, 2024 06:03 |
|
Ok, cool, just seemed like some interesting concepts. I remember my teacher doing casting in a different way, although it is possible I remember wrongly.
|
# ? Oct 31, 2012 08:02 |