c++

Dead code identification (C++)

I have a large legacy C++ project compiled under Visual Studio 2008. I know there is a reasonably amount of 'dead' code that is not accessed anywhere -- methods that are not called, whole classes that are not used. I'm looking for a tool that will identify this by static analysis. This question: Dead code detection in legacy C/C++ pro...

FFMPEG Frame to DirectX Surface

Given a pointer to an AVFrame from FFMPEG's avcodec_decode_video() function how do I copy the image to a DirectX surface? (Assume I have a pointer to an appropriately sized DX X8R8G8B8 surface.) Thanks. John. ...

Initializing a union with a non-trivial constructor

I have a structure which I create a custom constructor to initialize the members to 0's. I've seen in older compilers that when in release mode, without doing a memset to 0, the values are not initialized. I now want to use this structure in a union, but get errors because it has a non-trivial constructor. So, question 1. Does the de...

In C++, I want my interface, .h to say int GetSomeInt() const;.... but actually the method *DOES* update "this". Is there a way to do it without changing the .h?

I'm adding some lazy initialization logic to a const method, which makes the method in fact not const. Is there a way for me to do this without having to remove the "const" from the public interface? int MyClass::GetSomeInt() const { // lazy logic if (m_bFirstTime) { m_bFirstTime = false; Do something once ...

C++ Serialization Performance

Hi! I'm building a distributed C++ application that needs to do lots of serialization and deserialization of simple data structures that's being passed between different processes and computers. I'm not interested in serializing complex class hierarchies, but more of sending structures with a few simple members such as number, strings ...

Date/time conversion: string representation to time_t

What's the best way to convert a date string, formatted as "MM-DD-YY HH:MM:SS", to a time_t value in either C or C++? ...

Enum C++ Get by Index

Hi, I was wondering in C++ if I have an enum can I access the value at the second index? For example I have enum Test{hi, bye}; if I want 'hi', can I do something like Test[0], thanks. ...

strptime() equivalent on Windows?

Is there a good equivalent implementation of strptime() available for Windows? Unfortunately, this POSIX function does not appear to be available. Open Group description of strptime - summary: it converts a text string such as "MM-DD-YYYY HH:MM:SS" into a tm struct, the opposite of strftime(). ...

c++ array declaration in a header

Hi, I was wondering if it is possible to declare an array (size not known at this time), as a private member of a class and later set the size in the constructor of the class. For example: class Test { int a[]; public: Test(int size); }; Test::Test(int size) { a[size]; // this is wrong, but what can i do here? } Is this possible o...

C++ STL Vector Iterator accessing members of an Object

Hi, I think I've declared a Vector with an object correctly. But, I don't know how to access it's members when looping with Iterator. In my code, the line --->> cout << " " << *Iter; How do I print the contents of the members? Like *Iter.m_PackLine ??? Not sure if I used the correct terminology, but appreciate the help! Thanks cl...

QAbstractTableModel inheritance vtable problem

Here's another problem with qt: I extend a QAbstractTableModel, but I get a compiling error ( I'm using cmake) // file.h #ifndef TABLEMODEL_H #define TABLEMODEL_H #include <QAbstractTableModel> class TableModel : public QAbstractTableModel { Q_OBJECT public: TableModel(QObject *parent = 0); int rowCount(const QModelIndex &parent = QM...

Send data over Internet

Hi Guys, I have a requirement to send some 100 bytes data over internet .My machine is connected to internet. I can do this with HTTP by sending requests and receiving responses. But my requirement is just to send data not receive response. I am thinking of doing this using UDP Client server program. But to do that I need to host UDP cl...

Displaying dereferenced STL iterators in gdb

I have an iterator to a map element, and I would like gdb to show me the values of the "first" and "second" elements of that iterator. For example: std::map<int,double> aMap; ...fill map... std::map<int,double>::const_iterator p = aMap.begin(); I can use p.first and p.second in the code, but can't see them in gdb. For what it's worth,...

How do I examine the contents of an std::vector in gdb, using the icc compiler?

I want to examine the contents of a std::vector in gdb but I don't have access to _M_impl because I'm using icc, not gcc, how do I do it? Let's say it's a std::vector for the sake of simplicity. There is a very nice answer here but this doesn't work if I use icc, the error message is "There is no member or method named _M_impl". There a...

Convert Fortran to C or C++

I have some numeric code that I need to convert to C or C++. I tried using f2c, but it won't work on the Fortran code. f2c complains because the code uses C style preprocessor directives (#include). The code's readme states that it is Fortran77, that works with the fort77 linker, that would expand those includes. Does anyone know how t...

Recommended way to initialize srand?

I need a 'good' way to initialize the pseudo-random number generator in C++. I've found an article that states: In order to generate random-like numbers, srand is usually initialized to some distinctive value, like those related with the execution time. For example, the value returned by the function time (declared in heade...

Export HTML to PDF (C++, Windows)

I am looking for a redistributable component to convert HTML to PDF. I would - at the moment - like to avoid using a "PDF printer", as this requires a printer installation and some user "playing around" in the printers panel might break that feature. The HTML is available in a Browser control or as external file. The HTML is normally f...

What's the Magic Behind Escape(\) Character

How does the C/C++ compiler manipulate the escape character ["\"] in source code? How is compiler grammar written for processing that character? What does the compiler do after encountering that character? ...

Simple script to count NLOC?

Do you know a simple script to count NLOCs (netto lines of code). The script should count lines of C Code. It should not count empty lines or lines with just braces. But it doesn't need to be overly exact either. ...

How can I make a CListCtrl keep its scrollbar?

In MFC, a CListBox has a "disable no scroll" property. When you set it to true, the vertical scrollbar is always there, no matter how many items you have. How can I do the same thing with CListCtrl? ...