|
Super Dude posted:How can I add elements to the beginning of a vector? I essentially want to merge a vector and a string, putting one ahead of the other. I was going to just take the characters from the string, starting with the end, and add them to the beginning of the vector. Unfortunately, I can only find the push_back function, which adds it to the end. Would it be ok to make the string into a vector, then tack on the other vector? I know that this was resolved, but why are you using a vector instead of a deque when you know that you'll be inserting at the beginning? Deques are designed to grow from both ends whereas vectors are not.
|
# ¿ Mar 9, 2008 23:23 |
|
|
# ¿ May 3, 2024 23:16 |
|
WalletBeef posted:Has anyone been able to get Purify 7.0 properly working with Visual C++ in Visual Studio 2008, if so, what did you have to do to get both pieces of software working correctly? It apparently doesn't work with VS 2008 PDB files. That' my guess, anyway. I was upgraded from 2005 to 2008 and started seeing exactly the problem that you describe. The good news is that the line numbers are accurate (though sometimes it will strangely specify the wrong object file). You just have to open them up outside of Purify.
|
# ¿ Mar 19, 2008 22:28 |
|
WalletBeef posted:Well, I installed VS 2005 and Purify is happy. It's showing line numbers, source code and all. Thanks a loving ton. np. I've tried various cl.exe and link.exe switches and I can't get VS2008 to generate the old-style PDB files. I'm a deeply lazy man, though, and don't feel like going back to 2005. I also have a weirdish development environment (I mount my windows drive from my mac and edit everything in vim), so I'm used to just opening the source files and finding the offending lines. Hopefully, though, IBM will release a fix soon enough. I don't know if you've tried dealing with IBM support yet but DO NOT attempt to submit this as a bug. You'll end up with a self-inflicted bullet wound.
|
# ¿ Mar 20, 2008 22:55 |
|
I came across this a year or two ago:rob pike posted:Simple rule: include files should never include include files. If instead they state (in comments or implicitly) what files they need to have included first, the problem of deciding which files to include is pushed to the user (programmer) but in a way that's easy to handle and that, by construction, avoids multiple inclusions. Multiple inclusions are a bane of systems programming. It's not rare to have files included five or more times to compile a single C source file. The Unix /usr/include/sys stuff is terrible this way. It made sense at the time and I've followed this rule ever since (it's Rob Pike for Christ's sake). But when it comes to libraries it starts to get overly tedious for people using your library. You don't want to have a monolithic header file (think of the sockets library only used one header) but you also don't want them to have to read comments in your headers to find dependencies. What do other people do? And yes, I do employ #ifdef guards on the header files as well.
|
# ¿ Mar 26, 2008 22:20 |
|
TSDK posted:Good christ, that guy's an idiot. Yes, Rob Pike is an idiot. Hey, at least my post generated more comments in this thread in 1 day than in the last week! What I generally do now is have a monolithic include file to distribute with my libraries, but within each project I adhere to Pike's Law. One distinct advantage that's come of this is is a better understanding of which components use which other components, making bad design is much more blatant. Note also that 95% of my code is c, not c++, so it's easier to get away with this approach. The real question is, how pissed off is the next developer to take over my projects going to be? Very, I assume. Well of course he's not infallible. I was just responding to TSDK casually dismissing the dude as an idiot when he's one of the better engineers of his time. vvvvvvvvvvvvvvvvvvvvvv Plastic Jesus fucked around with this message at 16:45 on Mar 27, 2008 |
# ¿ Mar 27, 2008 16:35 |
|
That Turkey Story posted:You don't think that adhering to this "law" is a bad design on it's own!? I just said that I don't do this for libraries for exactly the reasons you just listed. I do it within my own projects for exactly the reasons I just listed. I will probably flatten things when they go to release so that you do not kill me. But during development it is _nice_ to know where dependencies lie.
|
# ¿ Mar 27, 2008 17:30 |
|
Bush is a QT posted:I have a question about fflush(stdin) in C programming. Always flush shared file handles in multi-threaded applications. I can't for the life of my think of a time when multiple threads would be accessing stdin, but it happens all the time with stdout. If you have several threads that all want to print poo poo to the screen you have to make them stand in line to do so or they'll end up printing over the top of each other. So you make them acquire a mutex, then write to stdout. You want to flush stdout at that point to ensure that everything has been written before you release the mutex. Fake edit: just thought of when you'd want to fflush(stdin)- when your application will be used in a pipe, e.g. 'cat somefile|yourapp'.
|
# ¿ Apr 11, 2008 16:48 |
|
slovach posted:I guess this thread is the closest to what I'm looking for, not exactly C/C++ but rather the Win32 API. I'm not positive that I properly understood your question- are you trying to get the HWND associated with the thread in which you're executing? Look into EnumThreadWindows()- it does exactly what the name might imply.
|
# ¿ Apr 16, 2008 16:35 |
|
Like slovach, I have a Windows API question and don't know which thread is best. So I'm posting here. Did something happen to context menu creation in Vista? The following works just fine in every version of Windows except Vista (and actually works in Vista if you're using the Windows Classic theme): code:
Edit: Figured it out, and it had nothing to do with the actual menu creation. I didn't have 'default: return(DefWindowProc())' in my windows WindowProc. Sure am glad that it took me 4 days to figure out that I'm a retard. Plastic Jesus fucked around with this message at 15:30 on Apr 18, 2008 |
# ¿ Apr 17, 2008 17:12 |
|
I'm moving this here from the General thread, because this is where it belongs.clockwork automaton posted:It's okay though, because I figured it out. It was an issue with user space memory and kernel space memory all I had to do was use strcpy and it was saved. You've actually got quite a lot of bad going on with your code. I only glanced at the code up on pastebin, but I noticed these things: * You're allocating memory for 'name' in main() and never freeing it. What's worse is that you never actually use this memory since you later set name to point to something in argv[]. * You don't check the return value of any of your memory allocation routines, a tremendously bad idea. * In your vector_resize() function you will end up with members of your array pointing to bad memory since you do this: code:
|
# ¿ Apr 21, 2008 17:10 |
|
On the client: * You have a potential buffer overflow on line #66, since there won't be a null terminator (pass SLOTS as the length param to read_line). This could get messy on line 110 where you do an strlen() on the read buffer. You should also explicitly bzero() the input buffer. * You don't check to see if received is a valid pointer before you free() it. If someone does "9999" on the first turn, that'll crash. On the server: * You don't check to make sure that your calls to calloc() on liness #57 and #90 don't fail. * You don't check to ensure that input is non-NULL in the compare() function. You should also check to ensure that it is at least (SLOTS + 1) long. * You don't allocate any space for 'correct' on line 69. In fact, I think that your declaration will result in a const char *, not a char *, so the assignment on line 74 should fail spectacularly. That whole loop is kinda weird. Wouldn't something like this work just as well and more simply? code:
* I have no idea how RPC deals with freeing malloc()'d data, but hopefully it does since you never free anything.
|
# ¿ Apr 21, 2008 18:00 |
|
Harokey posted:I'm trying to integrate some UNIXy (cygwin) code over to a visual studio project. I've never really dealt with visual studio, or windows programming in general, so I'm having a lot of problems. Unless it's absolutely critical that you use MFC for thread management I recommend using the core Win32 thread management API calls. They're very straight-forward and in my opinion kick the tits off of pthreads. The SDK docs for threads and fibers are particularly good, so an afternoon of reading will more than cover what you need to know to get started.
|
# ¿ Apr 24, 2008 15:41 |
|
Professor Science posted:honestly, K&R is always a good idea. Learning to program by reading K&R is like learning French by reading Rimbaud. It can be done, but you're going to be confused, frustrated and it'll take you 3 times longer than necessary.
|
# ¿ May 13, 2008 16:44 |
|
Insurrectum posted:What's a way to determine the runtime of a program for something like a Project Euler problem? man time
|
# ¿ Jul 13, 2008 03:06 |
|
Is there a default XML parsing library that is guaranteed to be included on all versions of Windows since 2k SP4? It looks like MSXML 3.0 is only on XP and higher, 4.0 has to be installed separately and 5.0 only comes with Office 2003.
|
# ¿ Jul 16, 2008 19:51 |
|
Avenging Dentist posted:Why not just statically link to TinyXML or something if it's that big a deal? Because I'm supposed to remove any non-default dependencies for some unknown loving reason.
|
# ¿ Jul 17, 2008 04:10 |
|
I've beat my head against this for like 3 wasted hours and it must just be my misunderstanding of c++. In file some_consts.h I have code:
code:
code:
code:
code:
code:
code:
Compiler is VS2008.
|
# ¿ Apr 2, 2009 21:06 |
|
Avenging Dentist posted:EDIT: Didn't see the const. Const variables, by default, do have internal linkage. The "solution" doesn't actually solve anything though, because it still relies on a particular static initialization order. Yah, I tried that solution and it did nothing (except make the string empty in CLogger while have content in MyUtil). Adding static made no difference in either approach. Doing cost char* is just so ugly. And as a larger solution, how would I do this sort of thing with anything that's not a base type? Is it just not possible a namespace level?
|
# ¿ Apr 2, 2009 22:53 |
|
Avenging Dentist posted:What. Who cares? Anyone who wants to pass a const string& instead of a const char * to a function? Or anyone who wants to use template string constants to reduce pain when you need support unicode? If I just cared about solving this exact problem I'd have used a #define and moved on. Avenging Dentist posted:The link in Standish's post explains one (of several) solutions to the problem. Calling a function isn't really a solution to this problem. This is an extremely easy (and "effective" even) thing to do at the class level, I'm just wondering if it's something that can only be done within a class. And if so, why was that not mentioned in Meyers's book?
|
# ¿ Apr 2, 2009 23:40 |
|
|
# ¿ May 3, 2024 23:16 |
|
Avenging Dentist posted:Goddamn you're needlessly a prick. I have this question because I've done the exact same thing with the CString in MFC (which does use templates, exactly for the reason I talked about) and haven't run into this problem. OMG I HAVE A STRING LITERAL IN MY CODE JESUS WHAT WILL I DO? const CString OhGodYouInternetPosters(_T("You piss me off so much you stupid newbie programmers who have questions about books")); Thanks for all the help though, you self-satisfied and condescending oval office.
|
# ¿ Apr 3, 2009 00:36 |