c++

Is list::size() really O(n)?

Recently, I noticed some people mentioning that std::list::size() has a linear complexity. According to some sources, this is in fact implementation dependent as the standard doesn't say what the complexity has to be. The comment in this blog entry says: Actually, it depends on which STL you are using. Microsoft Visual Studio V6 ...

Dead code detection in legacy C/C++ project

How would you go about dead code detection in C/C++ code? I have a pretty large code base to work with and at least 10-15% is dead code. Is there any Unix based tool to identify this areas? Some pieces of code still use a lot of preprocessor, can automated process handle that? ...

Native VC++ using external (not project) dll reference how to specify path to dll

I have a native VC++ project that uses a dll (which is not in a project). Now, I must to put the dll in one the "Search Path Used by Windows to Locate a DLL" link but I don't want the dll to sit in the exectuable or current or windows or system directory. So my only option according to that is adding the path to the %PATH% environment...

C for loop implemented differently than other languages?

I read the following in a review of Knuth's "The Art of Computer Programming": "The very 'practicality' means that the would-be CS major has to learn Kernighan's mistakes in designing C, notably the infamous fact that a for loop evaluates the for condition repeatedly, which duplicates while and fails to match the behavior of most other ...

Difference between files writen in binary and text mode

What translation occurs when writing to a file that was opened in text mode that does not occur in binary mode? Specifically in MS Visual C. unsigned char buffer[256]; for (int i = 0; i < 256; i++) buffer[i]=i; int size = 1; int count = 256; Binary mode: FILE *fp_binary = fopen(filename, "wb"); fwrite(buffer, size, count, fp_binary)...

Where are variables in C++ stored?

Where are variables in C++ stored? Inside the RAM or the processor's cache? ...

Counterpart of PHP's isset() in C/C++

PHP has a very nice function, isset($variableName). It checks if $variableName is already defined in the program or not. Can we build similar feature for C/C++ (some kind of symbol table lookup)? ...

Mixed Mode Library and CRT Dependencies - HELP

Alright, after doing a ton of research and trying almost every managed CPP Redist I can find as well as trying to copy my DLLs locally to the executing directory of the app I cannot figure out what dependencies i'm missing for this mixed mode library. Basically I have a large C# application and I'm trying to use a mixed mode library I m...

Can initialization list in constructors be used in template classes?

I find that most books concerning C++ templates don't tell anything about whether it's possible or not to use initialization list in constructor of a template class. For example, I have code like this: template <class T> class Stack { T* data; std::size_t count; std::size_t capacity; enum {INIT = 5}; public: Stack()...

Type Casting in C++

May be the question will be a little bit noobie, but can anybody advice me some books/sites/articles about how and when it's better to use typecasting in C++ style and when it would be better to prefer C-style? I've read a few books (Shildt, Eckel) and haven't found good material on this theme though I think it's one of the strongest C+...

Your least favorite C++ Coding guideline

Hi, As a counterpart to C++ Coding Guideline 102, which of the 101 guidelines of Sutter & Alexandrescu do you violate or ignore most often, and why? ...

C++ Error Handling -- Good Sources of Example Code?

Just about every piece of example code everywhere omits error handling (because it "confuses the issue" that the example code is addressing). My programming knowledge comes primarily from books and web sites, and you seldom see any error handling in use at all there, let alone good stuff. Where are some places to see good examples of C+...

std::string erase last character fails?

I'm trying to change user input in wildcard form ("*word*") to a regular expression format. To that end, I'm using the code below to strip off the '*' at the beginning and end of the input so that I can add the regular expression characters on either end: string::iterator iter_begin = expressionBuilder.begin(); string::iterator i...

Correct way to use custom functor with std::generate_n() algorithm?

The following code compiles correctly under VC++ 8 on XPSP3, but running it causes a runtime error. My header looks like: #include <stdexcept> #include <iterator> #include <list> template<typename T> class test_generator { public: typedef T result_type; //constructor test_generator() { std::generate_n( std:...

Window Handle and window dimension

The MFC application that i created is dialog based. Just one dialog thats all. How do I get the window handle to this window, while the application is performing the InitDialog. I need to find out its dimension as well. GetForegroundWindow not necessarily gives you the handle to this window that is loading up ...

A Strategy against Policy and a Policy against Strategy

When I first discovered the Strategy pattern, I was amazed of the seemingly endless possibilities it offered to me and my programs. I could better encapsulate my models' behaviour and even exchange this behaviour on the fly. But the strategy could also be used to to provide traits and payload to the containing object - data that was decl...

Is this prime generator inefficient C++?

Is this seen as an in efficient prime number generator. It seems to me that this is pretty efficient. Is it the use of the stream that makes the program run slower? I am trying to submit this to SPOJ and it tells me that my time limit exceeded... #include <iostream> #include <sstream> using namespace std; int main() { int testCa...

how-to initialize 'const std::vector<T>' like a c array

Is there an elegant way to create and initialize a const std::vector<const T> like const T a[] = { ... } to a fixed (and small) number of values? I need to call a function frequently which expects a vector<T>, but these values will never change in my case. In principle I thought of something like namespace { const std::vector<const T...

Tracing which process that has opened a particular file

Hi, From kernel mode in Windows I'm able to intercept and monitor virtually all actions performed on a particular disk. When a file is opened for any purpose I get an event. Now I want to trace which application that opened it. I think this should be possible but don't know how. I'm using the standard file management functions in Wind...

How do I Monitor Text File Changes with C++? Difficulty: No .NET

Use case: 3rd party application wants to programatically monitor a text file being generated by another program. Text file contains data you want to analyze as it's being updated. I'm finding a lot of answers to this question wrapped around FileSystemWatcher but let's say you are writing an application for a Windows machine and can't gu...