c++

Endianness conversion and g++ warnings

I've got the following C++ code : template <int isBigEndian, typename val> struct EndiannessConv { inline static val fromLittleEndianToHost( val v ) { union { val outVal __attribute__ ((used)); uint8_t bytes[ sizeof( val ) ] __attribute__ ((used)); } ; outVal = v; ...

map<int,int> default values

Hello. I have this : std::map<int,int> mapy; ++mapy[5]; Is it safe to assume that mapy[5] will always be 1? I mean, will mapy[5] always get the default value of 0 before '++', even if not explicitly declared, as in my code? Cheers ...

typedef declaration syntax

Some days ago I looked at boost sources and found interesting typedef. There is a code from "boost\detail\none_t.hpp": namespace boost { namespace detail { struct none_helper{}; typedef int none_helper::*none_t ; } // namespace detail } // namespace boost I didn't see syntax like that earlier and can't explain the sense of that....

I just don't get the C++ Pointer/Reference system.

I've never had problems with references as in Python (implicit) or PHP (explicit &). In PHP you write $p = &$myvar; and you have $p as a reference pointing to $myVar. So I know in C++ you can do this: void setToSomething( int& var ) { var = 123; } int myInt; setToSomething( myInt ); Myint is now 123, why? Doesn't & mean "memory a...

Including a C header which declares a variable called "new"?

I'm trying to use the OpenCA (libPKI) library in a C++ application. However, when including the file pki_x509_data_st.h the following code fragment is encountered: typedef struct pki_x509_callbacks_st { /* ---------------- Memory Management -------------------- */ void * (*new) (void ); void (*free) (void *x ); void * (*dup) ...

OpenSSL: SessionTicket TLS extension problem

Hello, I'm using an application which uses OpenSSL for client TLS side. We upgrade the OpenSSL version from 0.9.8e to 0.9.8k. And then TLS doesn't work... Wireshark shows that the new version (with OpenSSL 0.9.8k) sends the client hello packet with a SessionTicket extension - and the server side responds with a fatal internal error. T...

List iterator not dereferencable?

Hi All I get the error "list iterator not dereferencable" when using the following code: bool done = false; while (!_list_of_messages.empty() && !done) { // request the next message to create a frame // DEBUG ERROR WHEN NEXT LINE IS EXECUTED: Counted_message_reader reader = *(_list_of_messages.begin()); if (reader.has_m...

C++ String pointers

In my previous app I had an object like this: class myType { public: int a; string b; } It had a lot of instances scattered everywhere and passed around to nearly every function. The app was slow. Profiling said that 95% of time is eaten by the string allocator function. I know how to work with the object above, but not how to wor...

stringstream problem - vector iterator not dereferencable

Hello I've got a problem with the following code snippet. It is related to the stringstream "stringstream css(cv.back())" bit. If it is commented out the program will run ok. It is really weird, as I keep getting it in some of my programs, but if I just create a console project the code will run fine. In some of my Win32 programs i...

what does it mean to be "terminated by a zero"

I am getting into C/C++ and alot of terms are popping up unfamiliar to me. one of them is a varible or pointer that is terminated by a zero. What does it mean for a space in memory to be terminated by a zero. I am not sure if I am saying it correctly, if not then please correct me. Thanks! ...

Data structures with different sized bit fields...

If I have a requirement to create a data structure that has the following fields: 16-bit Size field 3-bit Version field 1-bit CRC field How would I code this struct? I know the Size field would be an unsigned short type, but what about the other two fields? ...

Where is the code generated for sqrt and __CIsqrt?

I set VC++ to generate ASM for a method which calls sqrt, to see if it's generating FPU or SSE instructions. However when sqrt is called, I don't see the ASM. I only see a call to some function __CIsqrt, which I assume is some system sqrt function. I can't see any ASM for that to know what it is doing? ...

Pass a Delphi class to a C++ function/method that expects a class with __thiscall methods.

I have some MSVC++ compiled DLL's for which I have created COM-like (lite) interfaces (abstract Delphi classes). Some of those classes have methods that need pointers to objects. These C++ methods are declared with the __thiscall calling convention (which I cannot change), which is just like __stdcall, except a this pointer is passed o...

Will exit() or an exception prevent an end-of-scope destructor from being called?

Let's say I have the following code: struct mytype { ~mytype() { /* do something like call Mix_CloseAudio etc */ } }; int main() { mytype instant; init_stuff(); start(); return 0; } Is that destructor guaranteed to be called even if exit() is used from somewhere inside start() ? ...

What does it mean "regular file" according to S_ISREG C/C++ ?

Hello all, Let's consider the following 3 code lines: struct stat buffer; status = lstat(file.c_str(), &buffer); bool Flag = S_ISREG(buffer.st_mode) When S_ISREG() returns true it tells you that the file is a regular file What does regular means exactly ? Thanks ...

How do I convert a range of integers into a list using C++

Hello, I have a string input of the format 1,3-7,10,11-15 I want to identify all the integers entered in the range. How do I achieve this using C++? TIA Guppy ...

Opinions regarding C++ programming practice

I have a program that I am writing, not too big. Apart from the main function, it has about 15 other functions that called for various tasks at various times. The code works just fine all in one file, and as it is right now. However, I was wondering if anyone had any advice on whether it is smarter/more efficient/better programming to p...

placement new to defer to a different constructor

Is this safe? I'm not using any virtual functions in my actual implementation, but I'm tempted to believe that even if I was, it would still be safe. class Foo { Foo() { // initialize things } Foo( int ) { new ( this ) Foo(); } } ...

C++: parsing with simple regular expression or shoud I use sscanf?

I need to parse a string like func1(arg1, arg2); func2(arg3, arg4);. It's not a very complex parsing problem, so I would prefer to avoid resorting to flex/bison or similar utilities. My first approch was to try to use POSIX C regcomp/regexec or Boost implementation of C++ std::regex. I wrote the following regular expression, which does ...

In C++, how can I make typedefs visible to every file in my project?

I have a typedef typedef unsigned int my_type; used in a file. I would like to make it visible across all my files, without putting it in a header file included by everything. I don't want to go the header file route because as it stands this will be the only declaration in the header file (and it seems unnecessary to add a file just...