c++

How is the memory layout of a C/C++ program?

I know that there are sections like Stack, Heap, Code and Data. Stack/Heap do they use the same section of memory as they can grow independently? What is this code section? When I have a function is it a part of the stack or the code section? Also what is this initialized/uninitialized data segment? Are there read only memory section a...

How do I use DrawPrimitiveUP so it uses the color value from my defined struct ?

I need to draw lines using DrawPrimitiveUP and I need it to use the color value from my defined structure. Important snippets from the code: struct PointVertexColor { float x, y, z; // Position DWORD color; //Colour }; #define D3DFVF_PointVertexColor ( D3DFVF_XYZ | D3DFVF_DIFFUSE ) PointVertexColor myLines[1024]; device->Draw...

C++ reference variable across files

I have a project where I need to reference a variable declared in one CPP file in another, is that possible? If so, how? ...

Running a process from memory C/C++

My function: /* --_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_ runPE( dosheader ptr, ntheader ptr, sectionheader ptr, ptr to exebuffer, DWORD SizeOfImage(Alignment fixed)) _--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_--_-- */ int runPE2(IMAGE_DOS_HEADER* pDOS,IMAGE_NT_HEADERS * pNT...

C++ TLS, somethings wrong...

I'm learning about Thread Local Storage... (TLS) Here is my TLS Alloc code: //global variable DWORD g_dwTlsIndex; //inside DLLMain: int val= 5; switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: g_dwTlsIndex = TlsAlloc(); if ((g_dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) { printf("No more indexes available"); } ...

Ampersand accelerators cause a beep in a Win32 dialog

I have a dynamically created toolbar on a plain Win32 dialog. My buttons are added with & shortcuts which correctly puts underscore to characters following ampersand but pressing Alt+(char) causes a beep and the button is not clicked. It has been a while since I have done Win32 API development. Is there something that needs to be done t...

NetBeans6.9 C++ runtime error

In NetBeans 6.9 in windows version I use CygWin for C++ programming.I can compile my simple program and BUILD SUCCESSFUL message show by output window in NetBeans but when run my project this message show in external terminal : /cygdrive/c/Users/SjB/Documents/NetBeansProjects/CppApplication_3/dist/Debug/Cyg win-Windows/cppapplication_3....

'this' pointer in macro and function

Hello guys, I have some code which use 'this' pointer of class which calls this code. For example: Some::staticFunction<templateType>(bind(FuncPointer, this, _1)); Here is I'm calling bind function from boost. But it doesn't matter. Now I have to wrap this code. I made a macro: #define DO(Type, Func) Some::staticFunction<Type>(bind(F...

Game development, which way to go

Hey, Ever since I started playing games, I wanted to develop my own, simple and later more complex game. At the moment I earn my share with programming web applications and doing some simple game development in my free time. As for my programming experience. I have good knowledge of almost anything web related (PHP, AJAX, JS, etc.). T...

Read and output possible unicode torrent contents in C++?

I'm trying to write a simple C++ program to open a torrent file (Passed through argv[1]), read all of it, and then print the entire file's contents verbatim with no alterations, it has to print a carbon copy of the original torrent. The issue is, some of the torrents may contain Japanese, Russian, etc. (FIlenames, description, etc.)... A...

Number of arguments in macro definition

Hello, I have some templated function which has different number of arguments due to the template-type. This function is wrapped with macro definition. #define SomeTemplate(TemplateType, Arguments) someFunc<TemplateType>(Arguments); Everything is okay until I'm using only 1 argument for function calling. But I need in more. I looked a...

Correct data structure to use for (this specific) expiring cache?

I need to read from a dataset which is very large, highly interlinked, the data is fairly localized, and reads are fairly expensive. Specifically: The data sets are 2gigs - 30gigs in size, so I have to map sections of the file into memory to read. This is very expensive compared to the rest of the work I do in the algorithm. From pr...

Flexible mutation of sequence containers in C++

I'm pondering a current limitation of STL iterators and wondering if there's an elegant way around it. Here's my situation: I have a class that encapsulates a sequence container and a generic method to mutate the contents of the container, for example: class Container { typedef std::vector<int> Data; Data data_; public: template ...

Qt multiple key combo event

Hi guys, I'm using Qt 4.6 and I'd like to react to multi-key combos (e.g. Key_Q+Key_W) that are being held down. So when you hold down a key combo, the event should be called all the time, just the same way as it works with single key events. I tried to use QShortcuts and enable autorepeat for them, but that didn't work: keyCombos_.pus...

Custom iterator: how do I keep track of it?

I have this situation: I have a class which keeps track of an array of pointers. I built a custom iterator which loops through this array. My problem is on how to make it threadsafe, especially while incrementing/decrementing? Here is a draft of the relevant parts of what I have: typedef fruit * iterator; class fruits { private: ...

Why aren't (C++) virtual destructors enforced for a base class

Destructors aren't virtual by default to not hurt when its not needed, which is fine. But in case of a base class derived class scenario, is there any use case for not having a virtual destructor? If not could it be possible (does it make sense) for the compiler to complain if a class derives from a base class which has a public non vir...

porting DevC++ to linux

Hi folks, I wanted to use DevC++ on Linux, so I've started it with wine and everything is OK until it came to run the file. The C file compiles well and a .exe files generated that is able to run on Linux (without wine) $ file '/media/F6AC746BAC74286F/Dev-Cpp/work/hello_on_nix.exe' /media/F6AC746BAC74286F/Dev-Cpp/work/hello_on_nix.ex...

How to read a line from a text file in c/c++ ?

After exhaustive googling and visiting many forums, I am yet to find a good comprehensive answer for this question. A lot of the forums suggest using the get line istream& getline (char* s, streamsize n ) function. My question is what if I don't know what the length of each line is and cannot predict what the size may be? Also what is i...

What is the difference between r-value references and l-value references? (CodeGen)

What does an r-value reference look like from a lower-level perspective. I just can't seem to wrap my head around it! Can I see an example of generated code (either equivalent C or x86/x64) from a r-value reference vs. a l-value reference? For example, what would this construct look like? Let's assume no copy elision for now. vector<So...

QTableView sorting signal?

I use QTableView + QStandardItemModel to show some data (data stored in some other data structure), and this table view is sortable. Since it is sortable, when sorting this model, I also need to sort the order of stored data. I try to implement a slot for the sorting signal, but I don't know what signal is emitted when clicking the head...