|
From what I could tell at the career fair earlier this week, certain companies local to where I go to school seem to make a lot of devices where C is important. Motorola Solutions, for one. whoops page snipe. i don't really know if that's a fact, though.
|
# ? Sep 23, 2017 17:06 |
|
|
# ? Jun 8, 2024 18:52 |
|
Yeah C remains important, and I don't really want to poo poo on the language too much, it just requires people to put up with a lot of bullshit. I wouldn't wanna talk anyone out of learning it.
|
# ? Sep 23, 2017 17:07 |
|
It's hard to really get a handle on the low-level stuff if you don't see it early. And it's easier to appreciate the benefits of newer languages/libraries if you see how lovely the old ones were. Plus, you are very likely to run into a library that uses the old poo poo somewhere, and it's good to have some sense of these peculiarities starting out. I do appreciate learning all the way down to assembly language when I was in high school and undergrad, and even digital system design, although I think a project where we would actually write a tiny bit of machine code would have been really neat.
|
# ? Sep 23, 2017 17:11 |
|
I think I'd rather teach assembly than C, though I spent at least a decade writing large-scale C code on purpose and with a smile. But yeah, it's still useful. Oh well.
|
# ? Sep 23, 2017 17:16 |
|
Subjunctive posted:Why do they even let beginners use C?
|
# ? Sep 23, 2017 18:20 |
|
Sure, but why let them test out of machine code via hexl-mode?
|
# ? Sep 23, 2017 18:39 |
|
C is like portable machine code. The, uhh, register allocator isn't a good intro lesson I'm afraid.
|
# ? Sep 23, 2017 18:42 |
|
Naive register allocator is super easy: assume that only stack and pc pointers are preserved across load/operate/store "instructions". It's slow, but it's what everyone's first compiler does to start.
|
# ? Sep 23, 2017 18:49 |
|
It's like they say: you can't build anything with LEGO until you've mastered injection moulding.
|
# ? Sep 25, 2017 14:37 |
|
I have a question about getting a value at a specific position in a std::list. Full disclosure: this is part of a homework assignment, but it's only one part of it (in other words, getting a value isn't the entire assignment). If this is against the rules of the thread, I'll withdraw the question. The task at hand is to convert a program from using a dynamic array to std::list. One of the functions takes a single parameter, an unsigned int, and is supposed to return a value (of another class type) in the array at the specified position. After looking it up on cplusplus.com, my solution was to do something like this: C++ code:
Is there a better way to do this that actually compiles?
|
# ? Sep 26, 2017 02:07 |
|
F_Shit_Fitzgerald posted:I have a question about getting a value at a specific position in a std::list. Full disclosure: this is part of a homework assignment, but it's only one part of it (in other words, getting a value isn't the entire assignment). If this is against the rules of the thread, I'll withdraw the question. For solving your immediate problem: take a look at the function signature of std::advance. You can ignore the template parameters. What can you tell about the function from this? void advance( InputIt& it, Distance n )
|
# ? Sep 26, 2017 02:16 |
|
Fergus Mac Roich posted:For solving your immediate problem: take a look at the function signature of std::advance. You can ignore the template parameters. What can you tell about the function from this? That it requires a const_iterator? I changed that in the code, and it accepted the line declaring the list iterator. In other words: code:
code:
|
# ? Sep 26, 2017 02:26 |
|
Look at the return type of advance
|
# ? Sep 26, 2017 02:28 |
|
Doc Block posted:Look at the return type of advance Oh. I was so busy trying to find a solution that I missed that completely. Thanks for the help! Back to the drawing board.
|
# ? Sep 26, 2017 02:30 |
|
F_Shit_Fitzgerald posted:Oh. I was so busy trying to find a solution that I missed that completely. Perhaps std::next
|
# ? Sep 26, 2017 03:34 |
F_Shit_Fitzgerald posted:Oh. I was so busy trying to find a solution that I missed that completely. Well, after calling std::advance, you've got an iterator that has advanced as far as you wanted it to advance. What can you now do with that iterator?
|
|
# ? Sep 26, 2017 05:20 |
|
VikingofRock posted:Well, after calling std::advance, you've got an iterator that has advanced as far as you wanted it to advance. What can you now do with that iterator? I actually figured it out, thanks to your help and Stack Exchange. This code probably won't win any design awards, but it's functional: code:
|
# ? Sep 26, 2017 05:32 |
F_Shit_Fitzgerald posted:I actually figured it out, thanks to your help and Stack Exchange. Yup, you got it! The only other thing that I was trying to hint at there was that your for loop is equivalent to your call to std::advance. So you can do C++ code:
VikingofRock fucked around with this message at 07:48 on Sep 26, 2017 |
|
# ? Sep 26, 2017 07:45 |
|
VikingofRock posted:Yup, you got it! The only other thing that I was trying to hint at there was that your for loop is equivalent to your call to std::advance. So you can do Ohh! That makes sense. I guess I just haven't been understanding iterators quite as well as I thought. I might rewrite the loop this way, since I have a feeling my prof will be happier with this version than the somewhat clunkier version I wrote. Thank you all for the help! You helped me figure this out without just giving me the answer, which is exactly what I needed/wanted.
|
# ? Sep 26, 2017 18:04 |
|
I don't mean to turn this thread into my own personal homework help desk, but I'm absolutely at a loss for what to do with the one thing left to do in this assignment. In the original code, my professor wrote a lambda function that uses std::sort to arrange the dynamic array in ascending order: code:
code:
...and points to this line in stl_algo.h: code:
Edit: It was late and I was tired when I wrote this. F_Shit_Fitzgerald fucked around with this message at 07:38 on Sep 27, 2017 |
# ? Sep 27, 2017 07:03 |
|
F_Shit_Fitzgerald posted:uses std::sort to arrange the dynamic array in ascending order: std::list isn't a dynamic array, it's a linked list. F_Shit_Fitzgerald posted:because the list contains a combination of strings and floats, I'm not sure it'd behave properly. what
|
# ? Sep 27, 2017 07:27 |
|
b0lt posted:std::list isn't a dynamic array, it's a linked list. Right. The assignment is to convert all instances of dynamic arrays to using standard lists.
|
# ? Sep 27, 2017 07:30 |
|
Yeah, std::sort requires random-access iterators. I don't know what your professor is asking here; presumably not that you rewrite std::sort or hack the iterator type to pretend to be random-access when it isn't.
|
# ? Sep 27, 2017 07:49 |
|
Or use std::list::sort. Also that lambda body doesnt look quite right.
|
# ? Sep 27, 2017 08:16 |
|
F_Shit_Fitzgerald posted:
|
# ? Sep 27, 2017 17:38 |
I'm making a geometry system, and as part of that I have a static polygon class whose vertices and edges are known at compile time. For cache purposes I want to make a templated class that takes number of vertices and number of edges, so that all geometry data is continuous in memory. However, I have an issue that the virtual intersect function for static polygons on my Shape superclass is complaining about not having the template arguments. Also, I'm not actually sure how to provide the vertices through an initializer list to the constructor. My shape class: C++ code:
C++ code:
C++ code:
Joda fucked around with this message at 17:56 on Sep 27, 2017 |
|
# ? Sep 27, 2017 17:52 |
|
If your primary use for this type is dynamic in the number of vertices, you’re not really getting anything by templating it, because you’ll have to do something to reintroduce that dynamicism.
|
# ? Sep 27, 2017 18:02 |
Oh right. I also just realized that the offset between the two arrays won't be known by the compiler if it has to treat them as the same object type. I guess I'll just go with vectors for now and revisit this if it proves unperformant. Thanks.
|
|
# ? Sep 27, 2017 18:08 |
So I've got a question on linking on OS X, which I hope falls under the purview of this thread. I'm trying to get an executable to correctly link to a library in an unusual location (I'm pretty sure the version available in homebrew has a bug which I am trying to track down, so I can submit a patch). Currently I am linking with the commandcode:
|
|
# ? Sep 27, 2017 23:41 |
|
VikingofRock posted:So I've got a question on linking on OS X, which I hope falls under the purview of this thread. I'm trying to get an executable to correctly link to a library in an unusual location (I'm pretty sure the version available in homebrew has a bug which I am trying to track down, so I can submit a patch). Currently I am linking with the command I don't know what's going wrong in your case, but install_name_tool allows you to modify those paths after the fact (which is also helpful if you want to include .dylibs in your .app-bundle).
|
# ? Oct 3, 2017 09:38 |
y_y posted:I don't know what's going wrong in your case, but install_name_tool allows you to modify those paths after the fact (which is also helpful if you want to include .dylibs in your .app-bundle). Thanks, this is helpful to know for the future. For this case I ended up just adding a temporary symlink in /use/local/lib/ while I was debugging things.
|
|
# ? Oct 3, 2017 09:47 |
|
If my program crashes on somebody's machine, I want it to log the callstack, and create a crash dump file. I'm using this StackWalker library, which appears to do what it says on the tin, as far as generating a callstack. But how do I catch a crash? Of course, I have no idea where my program is going to crash, so I'm wrapping the entirety of main() in a __try/__except block, just like the example given: code:
1>c:\users\dwlem\documents\mymusic\mymusic.cpp(7592): error C2712: Cannot use __try in functions that require object unwinding My main() is about 1000 lines of random poo poo that I'm trying to encapsulate in the block. Is this the right way to catch a crash? I don't know what to do with this error, nor do I have any idea how exceptions work.
|
# ? Oct 18, 2017 23:35 |
|
Oh, the solution is to literally move my code elsewhere and do this:code:
|
# ? Oct 19, 2017 01:49 |
|
It looks like __try is some non-standard Microsoft thing. Like they bolted exceptions onto C.
|
# ? Oct 19, 2017 02:01 |
|
Windows has SEH exceptions in addition to C++ ones, __try __catch is for the SEH ones.
|
# ? Oct 19, 2017 02:07 |
|
Doc Block posted:It looks like __try is some non-standard Microsoft thing. Like they bolted exceptions onto C. Correct — he’s doing Win32 “structured exception handling” which is the OS-level debugging facility for doing poo poo in response to process-ending conditions. Segfaults, illegal instructions, uncaught C++ exceptions, etc all pass through this system before the big exit(). baby puzzle posted:Oh, the solution is to literally move my code elsewhere and do this: The short version is that you can’t mix C++ exceptions and SEH exceptions in a top-level SEH block, because it’s not sure what objects need to get their destructors run. When it’s in a helper function, the compiler can say “okay I know I need to unroll all objects up to this function call boundary.” Also, fwiw, doing crash handling in-process is really unreliable, because its not guaranteed if you have the CRT state / free memory / unmolested stack to do a bunch of poo poo in the same process right after catching the exception. I’d strongly suggest using a watcher thread with preallocated space to do this, or better yet, a separate watcher process. Check out the Breakpad library, which is used for crash reporting for both Firefox and Chrome (and untold other products).
|
# ? Oct 19, 2017 02:17 |
|
ullerrm posted:Also, fwiw, doing crash handling in-process is really unreliable, because its not guaranteed if you have the CRT state / free memory / unmolested stack to do a bunch of poo poo in the same process right after catching the exception. I’d strongly suggest using a watcher thread with preallocated space to do this, or better yet, a separate watcher process. Check out the Breakpad library, which is used for crash reporting for both Firefox and Chrome (and untold other products). How would you handle a crash outside of the process? That doesn't even make any sense to me. Can one thread or process watch for a crash in another? Breakpad looks like overkill and I don't think I could ever get it working anyway.
|
# ? Oct 19, 2017 02:46 |
|
I feel like replacing "// do some ugly stuff" with one's entire program is a good indicator that something is wrong. C++ Core Guidelines E.17 and E.18 come to mind. To be fair, I've never tried to do the whole "send information about this crash to the developers" thing but I can't imagine that a whole-program try/catch could ever be a sensible method of going about it.
|
# ? Oct 19, 2017 02:47 |
|
I don't know any better? There isn't supposed to be any exceptional behavior happening anywhere in my code, anyway. The guidelines aren't useful: "Let an exception propagate until it reaches a function that can handle it." Ok, well, none of my code is handling any exceptions at all. e: I guess I could follow that guideline, if I had the foresight to know where my program might unexpectedly... But.. that's stupid. baby puzzle fucked around with this message at 03:05 on Oct 19, 2017 |
# ? Oct 19, 2017 03:02 |
|
|
# ? Jun 8, 2024 18:52 |
|
You don’t know which parts of your code might generate exceptions or what those exceptions are likely to be?
|
# ? Oct 19, 2017 03:17 |