|
So I need to take a C/C++ "quiz" as part of a job hiring process. While I've taken courses in it and have worked with it, I've been using predominantly IDL and Python as of late, which aren't really the same. I'm worried that I am going to be rusty! Are there any good "review" resources for covering general concepts again? I've got my old text books, but I need less first-time stuff and more "remember this?"
|
# ? Aug 30, 2011 21:06 |
|
|
# ? Jun 9, 2024 00:24 |
|
GrumpyDoctor posted:What kinds of things can I expect On Itanium-ABI platforms, it should catch everything, even "foreign" exceptions (i.e. exceptions not thrown by C++ code). It does not, however, prevent setjmp/longjmp pairs from skipping over you. Also, note that the unwinder has heuristics for when it's reached the top of the stack that can sometimes inappropriately trigger if you try to unwind through a function that doesn't have unwind information. On Windows, it should catch anything thrown by C++, but I think it doesn't actually catch native SEH exceptions. Could be wrong, though.
|
# ? Aug 30, 2011 21:40 |
|
I'm setting up another computer in my 2nd office exclusively for studies/programming. I've noticed that a lot of the resources I'm using suggest using Linux or Unix as a development platform and I think now would be a great opportunity to use something besides Windows. The problem is that my spare computer is a refurbished Gateway E3600 (P4, 512MB Ram, AGP, CDROM, 20GB HD). I know I could probably dual boot from my other comp but the idea is to separate the computers I use for entertainment for study. So I need a distribution that is light on resources and some direction on how I can set it up as a development platform. Just pointing me to a well known eguide would be sweet. (or I could build a new PC....) Sephiroth_IRA fucked around with this message at 21:46 on Aug 30, 2011 |
# ? Aug 30, 2011 21:42 |
|
rjmccall posted:On Windows, it should catch anything thrown by C++, but I think it doesn't actually catch native SEH exceptions. Could be wrong, though.
|
# ? Aug 30, 2011 22:33 |
|
Mustach posted:With msvc, catch(...) will grab SEHs with the /EHa flag. (Source) I figured out the problem anyway, but this looks like what I needed. Thanks!
|
# ? Aug 30, 2011 22:52 |
|
/EHa has potentially nontrivial performance implications and makes it possible to cause hilarity by accidentally swallowing access violation, so if it's practical to do so it's usually better to use __try/__except.
|
# ? Aug 30, 2011 23:15 |
|
I was only going to be using it for finding specific problems like this, but __try/__except is another thing I didn't know about that looks better.
|
# ? Aug 30, 2011 23:23 |
|
Ran into this in some bare-metal code at work (names obfuscated)code:
2. what is the point of including "volatile" in the cast?
|
# ? Aug 31, 2011 22:14 |
|
TasteMyHouse posted:1. This kind of lvalue cast is not legal C, is it? or is it okay because the cast happens before the pointer dereference? It's okay because the cast happens before the pointer dereference. That makes this not an "lvalue cast": it's just a normal cast of an r-value, and it happens to occur during the computation of something that will ultimately be used as an l-value. TasteMyHouse posted:2. what is the point of including "volatile" in the cast? Hard to say without knowing the context. Accessing a volatile object in C/C++ means that the compiler is supposed to do exactly the operation requested at exactly that point in the execution sequence. It's mostly useful with memory-mapped I/O where loads and stores actually have arbitrary side-effects.
|
# ? Aug 31, 2011 22:35 |
|
Assuming BaseAddress isn't a char/void* (or uint32_t* I guess but then the cast is pointless) that's an aliasing violation. volatile happens to disable the sort of optimizations that make aliasing violations a problem but it's still undefined behavior.
|
# ? Aug 31, 2011 22:40 |
|
Plorkyeran posted:Assuming BaseAddress isn't a char/void* (or uint32_t* I guess but then the cast is pointless) that's an aliasing violation. volatile happens to disable the sort of optimizations that make aliasing violations a problem but it's still undefined behavior. BaseAddress is declared as a uintptr_t. I should also say that this function is one of 3 otherwise identical functions -- the other ones cast it to volatile uint16_t * and volatile uint8_t *
|
# ? Aug 31, 2011 23:00 |
|
I'll grant that I have an older computer, but I feel like with Eclipse CDT that my project is taking too long to compile. When I'm making, say, a 10 line update I am hoping I can have the compiler turn around on that code very rapidly so I can tell if I'm screwing it up or not. Instead I build the project, which leads me to distractions and loss of concentration. Is there anything Eclipse has to make that a bit quicker?
|
# ? Sep 1, 2011 04:11 |
|
Rocko Bonaparte posted:I'll grant that I have an older computer, but I feel like with Eclipse CDT that my project is taking too long to compile. When I'm making, say, a 10 line update I am hoping I can have the compiler turn around on that code very rapidly so I can tell if I'm screwing it up or not. Instead I build the project, which leads me to distractions and loss of concentration. Is there anything Eclipse has to make that a bit quicker? Depending on what is slowing down the build, precompiled headers may help. note that this actually doesn't have anything to do with Eclipse itself, but is a feature of GCC
|
# ? Sep 1, 2011 06:01 |
|
Rocko Bonaparte posted:I'll grant that I have an older computer, but I feel like with Eclipse CDT that my project is taking too long to compile. When I'm making, say, a 10 line update I am hoping I can have the compiler turn around on that code very rapidly so I can tell if I'm screwing it up or not. Instead I build the project, which leads me to distractions and loss of concentration. Is there anything Eclipse has to make that a bit quicker? It depends on what you're changing in your code; if you're modifying header files that are used by lots of other files then long compile times are unavoidable, unless you have a way of isolating that header file somehow so that the system doesn't need to recompile all the things that depend on it. One thing you can do is make a number of testbed projects, with each one containing a subset of your code base. For example, if you have a set of file reading classes, you could make a project that contains just those classes and what they depend on them, but nothing that depends on them. Then, when you change those classes, you can test compile in that project to make sure there are no errors before going back to recompile the main project. Another option is to split parts of your code off into statically linked libraries, with each library containing the code for a particular subsystem. Then, when you're working on a subsystem, you can recompile the library for it separately. The latter option is definitely preferable, but might be a hell of a lot more work to sort out compared to the former one. Edit: Also, quick semantic question since I just really confused myself writing this. If I say "A and it's dependencies", does that mean "A and the things A depends on" or "A and the things that depend on A"? Gerblyn fucked around with this message at 11:14 on Sep 1, 2011 |
# ? Sep 1, 2011 11:10 |
|
Gerblyn posted:Also, quick semantic question since I just really confused myself writing this. If I say "A and it's dependencies", does that mean "A and the things A depends on" or "A and the things that depend on A"? If I heard you say that I would think you meant the former.
|
# ? Sep 1, 2011 13:19 |
Zorak posted:So I need to take a C/C++ "quiz" as part of a job hiring process. While I've taken courses in it and have worked with it, I've been using predominantly IDL and Python as of late, which aren't really the same. I'm worried that I am going to be rusty! It's not a review resource per se, but looking over the C++ FAQ lite might help.
|
|
# ? Sep 1, 2011 14:26 |
|
Gerblyn posted:Edit: Also, quick semantic question since I just really confused myself writing this. If I say "A and it's dependencies", does that mean "A and the things A depends on" or "A and the things that depend on A"?
|
# ? Sep 1, 2011 16:22 |
|
rjmccall posted:Hard to say without knowing the context. Accessing a volatile object in C/C++ means that the compiler is supposed to do exactly the operation requested at exactly that point in the execution sequence. It's mostly useful with memory-mapped I/O where loads and stores actually have arbitrary side-effects. I've used this at work before. The volatile is required for accessing CSRs (Control & Status Registers) and MMIO (like he said above) so that you don't operate on cached values.
|
# ? Sep 1, 2011 17:53 |
|
bcrules82 posted:I've used this at work before. What's messing with me is that wouldn't you want to label the actual variable itself as volatile, and not the thing you're casting it to?
|
# ? Sep 1, 2011 17:56 |
|
TasteMyHouse posted:What's messing with me is that wouldn't you want to label the actual variable itself as volatile, and not the thing you're casting it to? code:
It may or may not be a volatile unit32_t*, so if you want to guarantee a 32-bit store to that location, that is how you do it. yes, you could do something like: code:
|
# ? Sep 1, 2011 18:11 |
|
"Dependencies" = stuff I depend on, "Dependents" = stuff that depends on me. The latter isn't used all that often because you usually don't know what third-party stuff other developers have created that depends on something you've written, while the set of your dependencies is pretty static. For example, using your package manager to install gcc + dependencies will install libc etc., but won't install gnuprolog and anything else that in turn depends on gcc. Because that would be a silly operation to want to perform.
|
# ? Sep 1, 2011 23:36 |
|
Jabor posted:"Dependencies" = stuff I depend on, "Dependents" = stuff that depends on me.
|
# ? Sep 2, 2011 01:07 |
|
Zorak posted:So I need to take a C/C++ "quiz" as part of a job hiring process. While I've taken courses in it and have worked with it, I've been using predominantly IDL and Python as of late, which aren't really the same. I'm worried that I am going to be rusty! A lot of these questions came up in my interview. Anything I didn't know I looked up, and for the most part could pass myself off as knowledgeable. Inheritance, virtual tables and recursion are most likely to come up.
|
# ? Sep 2, 2011 05:16 |
|
Zorak posted:So I need to take a C/C++ "quiz" as part of a job hiring process. While I've taken courses in it and have worked with it, I've been using predominantly IDL and Python as of late, which aren't really the same. I'm worried that I am going to be rusty! I don't know what level of experience they're looking for, but if they're looking for an intermediate-level knowledge of C++, I would say:
|
# ? Sep 2, 2011 07:28 |
|
Am I correct in assuming that the lifespan of a value used in an expression is the statement and that destructors will never be called until every operation in the statement happens? Or is there something else that determines destruction time for that? Also, considering that some compilers pad up the size of empty structures, is it guaranteed that a class that extends an empty structure will NOT padded at the start? MSVC clearly doesn't, but I'm not sure if it's standardized or not. OneEightHundred fucked around with this message at 17:35 on Sep 3, 2011 |
# ? Sep 3, 2011 17:31 |
|
OneEightHundred posted:Am I correct in assuming that the lifespan of a value used in an expression is the statement and that destructors will never be called until every operation in the statement happens? Or is there something else that determines destruction time for that? Temporaries created during the evaluation of an expression are destroyed in reverse order at the end of the evaluation of that full-expression, where things like if conditions are their own full-expression. The one exception is when an expression is used as the initializer of a reference variable or (in a constructor) member variable; in this case, if the reference is bound to a temporary, that temporary lives as long as the variable or constructor call. OneEightHundred posted:Also, considering that some compilers pad up the size of empty structures, is it guaranteed that a class that extends an empty structure will NOT padded at the start? MSVC clearly doesn't, but I'm not sure if it's standardized or not. The standard doesn't make any promises. Both MSVC and the Itanium ABI (i.e. most other compilers) try pretty hard to avoid adding unnecessary padding for empty subobjects. MSVC actually tries *too* hard, i.e., it has bugs and sometimes allocates different subobjects of the same empty type at the same address.
|
# ? Sep 3, 2011 23:00 |
|
I'm writing some regular expression code in flex, and I'm having a problem. I am trying to detect if there are non-printable characters inbetween a set of < >. For some reason, I can't figure out why my current solution is not working.code:
Any ideas?
|
# ? Sep 5, 2011 07:09 |
|
So what you're attempting to match is: 1. An open-< 2. Any characters as long as they aren't > 3. A non-printable character 4. Some more any-characters-that-aren't > 5. A close-> The regex you've got (with some liberties taken for whitespace): code:
|
# ? Sep 5, 2011 08:28 |
|
Jabor posted:So what you're attempting to match is: I guess I'm not seeing what I'm missing because from what I see, my regex matches the description.
|
# ? Sep 5, 2011 11:42 |
|
I hate regular expressions, a friend of mine once told me "So, you have a problem, and you decide to use regular expressions to fix it. Now, you have two problems." Anyways, are you sure you should be having the :print: in the first character set? It looks to me like the first character set is saying "Any character, except > or a printable character, repeated 0 or more times". Secondly, even if your rexexp worked, it would only find cases where a tag contained one non-printable character, if there were more than one, it would ignore it. I'm afraid I'm nowhere near good enough with these things to know how to fix it though.
|
# ? Sep 5, 2011 12:11 |
Gerblyn posted:I hate regular expressions, a friend of mine once told me "So, you have a problem, and you decide to use regular expressions to fix it. Now, you have two problems." If your problem really isn't any more complex, i.e. there are no more elements to your parser, then go write it by hand as a state machine, similar to what flex would output. State 0: Default state, between tags. If '<' is encountered, switch to state 1 and take note of where the '<' was encountered. If '&' encountered take note of the position and switch to state 3. If EOF, end processing. State 1: Inside tag. If '>' encountered, you have matched a valid tag and can use the current position along with the tag start position noted in state 0 to process the valid tag, then switch to state 0. If a non-printable is encountered, switch to state 2. If EOF, your file smells broken. State 2: Inside invalid tag. If '>' encountered, process your invalid tag then switch to state 0. State 3: Possibly an entity. For every character read, check the entire entity name read against your list of valid entity names, if what you have read is not a prefix of a valid one switch to state 0. If you match an entity name exactly, process it. (In reality this handling makes state 3 a sub-tree of a much more complex state machine. You can expand it in full if you like, switching state for every character read.) Of course, maybe you're required to use flex for some reason. In that case, good luck
|
|
# ? Sep 5, 2011 13:21 |
|
Super Dude posted:I'm writing some regular expression code in flex, and I'm having a problem. I am trying to detect if there are non-printable characters inbetween a set of < >. For some reason, I can't figure out why my current solution is not working. If you want to detect whether some non-printable characters are between < > you should just use \<[^[:print:]]*\>. Your regular expression doesn't do that, instead it is also trying to filter out strings like <>>^M>>^Z>> and <abc>>>>>.
|
# ? Sep 5, 2011 17:24 |
|
DeciusMagnus posted:If you want to detect whether some non-printable characters are between < > you should just use \<[^[:print:]]*\>. <valid stuff in a tag> ^M Not printable stuff outside a tag <valid stuff in a tag> The problem the original regexp has is in the second part of the regexp (thanks Jabor for breaking it into parts) - you have it matching NOT(> or printables), but you want it matching NOT(>) or printables. (ie. you have it matching NOT printables, but you want it to match printables.) I think in some regexp formats you could do that step like: (?:[^>]|[:print:])* But I don't know if flex will do that or not. Edit: Actually, you don't really need to do that anyway, just [^>]* would be fine - it doesn't matter if you accidentally match a non-printable character during that section because it will still have to match a non-printable afterwards in the third part. If you did it my complicated way your third part would match the first non-printable character, but if you do it the simpler way the third part would just match the last non-printable character in the tag. Edit2: Also you could have it match the first non-printable more simply with [^>]*? assuming the specific regexp parser supports that "match shortest" semantic. roomforthetuna fucked around with this message at 17:40 on Sep 5, 2011 |
# ? Sep 5, 2011 17:32 |
|
roomforthetuna posted:Edit2: Also you could have it match the first non-printable more simply with [^>]*? assuming the specific regexp parser supports that "match shortest" semantic. Unfortunately ? isn't supported (flex is stupid). \<([[:print:]]{-}[>\n<])*[^[:print:]][^>]*\> I think this fixed the problem. It looks horrible and is impossible to read, which really pisses me off. Super Dude fucked around with this message at 18:52 on Sep 5, 2011 |
# ? Sep 5, 2011 18:44 |
|
Super Dude posted:Unfortunately ? isn't supported (flex is stupid). Which is to say, I think \<[^>]*[^[:print:]][^>]*\> would work if all you need to do is detect that there is a non-printable in a tag.
|
# ? Sep 5, 2011 19:07 |
|
nielsm posted:This. flex supports conditional rules.
|
# ? Sep 5, 2011 20:01 |
|
I have a situation with RTTI that I'm trying to figure out if I can do the way I want. That being said I am pretty sure I can work around the issue if I must. Imagine I have list of pointers to a bunch of stuff of class "Fundamental." So we have stuff like: class A : public Fundamental class B : public Fundamental Let's throw in an interface for giggles: class IStuff. So let's add on: class C : public IStuff, public Fundamental class D : public IStuff, public Fundamental I have a list of Fundamentals, and my informal policy is I only put one of any particular subclass in. I don't know if that matters, but it's what I'm doing. Now I want to iterate the list and find, say, class A dynamically. This is easy enough with type_info checking. However, let's say I put in class C, and I want to see if anything in the list is an IStuff*. At compile time I can do this with dynamic_cast, but I'm lost about runtime. Any ideas? Oh yes the other way I was thinking I might get this to work is if I can add the IStuff to the list more explicitly, but I have to try it. In my particular situation IStuff is mostly-related to stuff that also implements Fundamental, so I could make IStuff subclass that, then have C and D subclass as usual. So that way I can pass an object of C to the list, but simultaneously cast it as an IStuff. So when I iterate and do type checks, I am hoping there it'll see the IStuff. Now then if I wanted to see if it had something of type C, I'm screwed. It's a game of whack-a-mole...
|
# ? Sep 5, 2011 20:12 |
|
Rocko Bonaparte posted:At compile time I can do this with dynamic_cast, but I'm lost about runtime. The entire point of dynamic_cast is that it checks at runtime.
|
# ? Sep 5, 2011 20:29 |
Plorkyeran posted:The entire point of dynamic_cast is that it checks at runtime. To elaborate, dynamic_cast<B*>(a) returns a B pointer if a has a dynamic type compatible with B, and returns 0/nullptr if a does not have a dynamic type compatible with B.
|
|
# ? Sep 5, 2011 20:33 |
|
|
# ? Jun 9, 2024 00:24 |
|
Rocko Bonaparte posted:However, let's say I put in class C, and I want to see if anything in the list is an IStuff*. At compile time I can do this with dynamic_cast, but I'm lost about runtime. Any ideas? code:
code:
But, frankly, I don't know why this compiles. My understanding of dynamic_cast is that it works up and down the inheritance hierarchy, but not sideways. Is that wrong? Is it really able to do arbitrary casting regardless of inheritance ancestry? edit: enshorten code Brecht fucked around with this message at 20:53 on Sep 5, 2011 |
# ? Sep 5, 2011 20:44 |