c++

Const in C

Quick question: int testfunc1 (const int a) { return a; } int testfunc2 (int const a) { return a; } Are these two functions the same in every aspect or is there a difference? I'm interested in an answer for the C-language, but if there is something interested in the C++ case I'd like to know as well. ...

C, C++, Java, what is next and what will it look like?

What do you think the next evolution of languages will look like? ...

Why use pointers?

I know this is a really basic question, but I've just started with some basic C++ programming after coding a few projects with high-level languages. Basically I have three questions: Why use pointers over normal variables? When and where should I use pointers? How do you use pointers with arrays? Also, can any of you recommend a go...

How can I detect if I'm compiling for a 64bits architecture in C++

In a c++ function I need the compiler to choose a different block if it is compiling for a 64 bit architecture. I know a way to do it for MSVC++ and g++, so i'll post it as an answer. However I would like to know if there is a better way (more elegant that would work for all compilers/all 64 bits architectures). If there is not a better...

How to setup VS2008 for efficient C++ development

Normally I program in C# but have been forced to do some work in C++. It seems that the integration with Visual Studio (2008) is really poor compared to C# but I was wondering if there are any good tools, plugins or configurations that can improve the situation. Another post pointed out the program Visual Assist X, which at least helps ...

How do I make a C++ macro behave like a function?

Let's say that for some reason you need to write a macro: MACRO(X,Y). (Let's assume there's a good reason you can't use an inline function.) You want this macro to emulate a call to a function with no return value. Example 1: This should work as expected. if (x > y) MACRO(x, y); do_something(); Example 2: This should not result...

Garbage with pointers in a class, C++.

I am using Borland Builder C++. I have a memory leak and I know it must be because of this class I created, but I am not sure how to fix it. Please look at my code-- any ideas would be greatly appreciated! Here's the .h file: #ifndef HeaderH #define HeaderH #include <vcl.h> #include <string> using std::string; class Header { public: ...

Generate a WSDL without a webserver

I would like to generate a WSDL file from a c++ atl webservice without using a web server. I would like to generate it as part of the visual studio build or as a post build event. I found a program (CmdHelper) that does this for .NET assemblies but it doesn't seem to work for what I need. Any ideas? ...

What are the lengths of common datatypes?

How many bytes would an int contain and how many would a long contain? Context: C++ 32 bit computer Any difference on a 64-bit computer? ...

Switching from std::string to std::wstring for embedded applications?

Up until now I have been using std::string in my C++ applications for embedded system (routers, switches, telco gear, etc.). For the next project, I am considering to switch from std::string to std::wstring for Unicode support. This would, for example, allow end-users to use Chinese characters in the command line interface (CLI). What ...

Why is fread reaching the EOF early?

I am writing a C library that reads a file into memory. It skips the first 54 bytes of the file (header) and then reads the remainder as data. I use fseek to determine the length of the file, and then use fread to read in the file. The loop runs once and then ends because the EOF is reached (no errors). At the end, bytesRead = 10624, ft...

On Win32 how do you move a thread to another cpu core?

I'd like to make sure that a thread is moved to a specific cpu core & can never be moved from it by the scheduler. There's a SetThreadAffinityMask() call but there's no GetThreadAffinityMask(). The reason I need this is because high resoultion timers will get messed up if the scheduler moves that thread to another cpu. ...

Docking a CControlBar derived window

How can I dock a CControlBar derived window to the middle of a splitter window (CSplitterWnd)? I would like the bar to be repositioned whenever the splitter is moved. To make it a little clearer as to what I'm after, imagine the vertical ruler in the Dialog Editor in Visual Studio (MFC only). It gets repositioned whenever the tree vie...

In c++, why does the compiler choose the non-const function when the const would work also?

For example, suppose I have a class: class Foo { public: std::string& Name() { m_maybe_modified = true; return m_name; } const std::string& Name() const { return m_name; } protected: std::string m_name; bool m_maybe_modified; }; And somewhere else in the code, I have something l...

How do you construct a std::string with an embedded null?

If I want to construct a std::string with a line like: std::string my_string("a\0b"); Where i want to have three characters in the resulting string (a, null, b), I only get one. What is the proper syntax? ...

How do I transfer a file using wininet that is readable by a php script?

I would like to transfer a text file to a webserver using wininet as if the file was being transferred using a web form that posts the file to the server. Based on answers I've received I've tried the following code: static TCHAR hdrs[] = "Content-Type: multipart/form-data\nContent-Length: 25"; static TCHAR frmdata[] = "file=filename...

C++ types using CodeSynthesis XSD Tree Mapping

Hi All, I'm using CodeSynthesis XSD C++/Tree Mapping utility to convert an existing xsd into c++ code we can populate the values in. This was we always make sure we follow the schema. After doing the conversion, I'm trying to get it to work so I can test it. Problem is, I'm not used to doing this in c++ and it's my first time with thi...

How do I read a text file from the second line using fstream?

Hello, how can i make my fstream object start reading a txt file from the second line? Thanks. ...

Can I use the STL if I cannot afford the slow performance when exceptions are thrown?

For example, I'm writing a multi-threaded time-critical application that processes and streams audio in real-time. Interruptions in the audio are totally unacceptable. Does this mean I cannot use the STL because of the potential slow down when an exception is thrown? ...

Is there a good way around the problems of structured exception handling (__try __except) with a multi-threaded server?

This article gives a good overview on why structured exception handling is bad. Is there a way to get the robustness of stopping your server from crashing, while getting past the problems mentioned in the article? I have a server software that runs about 400 connected users concurrently. But if there is a crash all 400 users are effec...