Runtime Library: multi-threaded variants have been seen to fail
[DLL/Static] | [Debug|Release]

Purpose: define a user defined stream buffer that processes each
incoming character and translates it to an encoded value. Place the
encoded character into a local buffer for output. The most simple case
would be an encoder that translates each character to upper case. A
more complicated case would be an encoder that encodes plain-text to
base64 encoding (this is not a one-to-one character encoding, it's a 3
character to 4character encoding, this is why an internal buffer is
needed)

Problem: The code throws an "Unhandled exception at 0x00529bcc in
hsl_d.exe: 0xC0000005: Access violation reading location 0x00000000."
after the "encoderbuf::underflow c = 51" character '3' has been read.
This basically tells me that deep down in the internals of the IO
library something is being dereferenced that is not allocated.

Question(s):
1) Does this occur with other compilers (requires testing)
2) Is this a problem with the IO library (unlikely I think)
3) Am I doing something stupid (more than likely) And if so what

Static constructors: a complex problem
&nbsp(112 Views)
Let's suppose that, under a particular platform,
the compiler doesn't initialize correctly the
global constructors and destructors at
startup.
The compiler is psp-gcc.
I have written two routines,
__do_constructor_initialization_aux
and
__do_destructor_initialization_aux
that, if recalled explictly by the code of
the program, start the routines generated
by the compiler and initialize the global
constructors (o deinitialize the constructors
when the program finish).
Unfortunately, each of this routine can access
only to the .ctor or .dtor section of the module
in which it is compiled, not to the .ctor or .dtor
section of different modules.
So, if you are compiling a project in C++ that
contains n files .o, **in each of these** a routine
__do_constructor_initialization_aux and
a routine __do_destructor_initialization_aux
must be present.
If the project has n object .o, there will be n
__do_constructor_initialization_aux routines and
n __do_destructor_initialization_aux routines.
N isn't a known number, because it depends from
the o. files that the programmer chooses to
create.
The trouble is the following: who start these
routines at startup
It is needed a special symbol in psp-gcc or in
psp-ld that makes that, at startup, before that
main () is executed, the cpu executes all
initialitation routines present in each module
that has been linked.
Any idea

copy constructor problem
&nbsp(108 Views)
On May 27, 11:07 am, ciccio wrote:
>
>
> I have a problem and I don't know what is going on here.
>
> I basically call a function defined as test(const bar &a), in which I
> define a const reference to an object foo which comes from bar. At this
> point I have a copy constructor which should not be the case.
>
> A working example you can find below which explains it a bit better.
>
> Am I just doing something stupidly wrong here
You aren't understanding that your bar:perator() is returning by
value, which creates a temporary object when it returns.

GDB debugger problem
&nbsp(118 Views)
hello ,
i was debugging a simple program using gdb debugger and when in
function display
on the simple line
cout

base classes and inheritance problem
&nbsp(111 Views)
, considering this code:
class A {
protected:
int n;
};
class B : public A {
public:
void setn(int k){ n = k;}
};
int main()
{
A *c;
c = new B();
c->setn(10);
return 0;
}
This of course will not compile, i'm trying to avoid using virtual
functions in class A and i was wondering if there exist a way of
achieving something like this code.

problem with unary_compose
&nbsp(161 Views)
hi
i'm trying to use the "functional extensions" of the stl.
having a "problem" with the unary_compose..
The following code seems right to me, but doesnt compile -
if i declare "operator()" of "struct one" as const it works - but
i dont understand why it has to be static .. !
#include
#include
#include
using namespace std;
using namespace __gnu_cxx;
struct one: public unary_function
{
int operator()(int arg)
{
return ++arg;
}
};
int main(int argc, char** argv) {
one o1,o2;
int i = 2;
unary_compose func = compose1(o1,o2);
cout

problems with std and const (inspectors)
&nbsp(114 Views)
Files:
pirma_lib.h - http://www.paste.lt/paste/de66c8b700...19eea1318d1993
pirma_lib.cpp - http://www.paste.lt/paste/050b916516...8f54a0193fe564
pirma.cpp - http://www.paste.lt/paste/6753553152...703393d79d6f67
I am using std:: in pirma_lib everywhere and this why I do not need to
use "using" and and std library which later could make some problems
and it still does now.
The problem is that when everything was in one file it was working
perfect and now I decided to put everything in separate files. This
way I made direct calls (std: and removed "using namespace std;"
from pirma_lib.cpp and this worked, I was able to compile this model (g
++ -Wall -ansi -pedantic -c pirma_lib.h);
But I was not able to compile the main code. Every line where I was
using "Aibe" class and it's methods was returning mistakes. But after
commenting "using namespace std;" in pirma.cpp I did not get any
error, but I should write to every cin, cout and etc std:: (make
direct calls).
The question would be how I should correctly move my class to separate
file, make module Why it throwing mistakes with that std (This one
makes the most problems as I can see);
- - -
The second question.
In pirma_lib.h there is a line: bool isSubSet(Aibe &other);
But I would like to protect "other" Aibe instance and use "const Aibe
&other", but inside it I am using length() method. (but I could easily
get directly if I need). And this throws another mistake, that I can
not use length() method in this case, but I then declare length: int
length() cent; This should mean that length() can not change *this and
I think that now it should allow me to call it, but again I am still
getting mistake that it can not find such method at all. (It might be
that I still does not understand how it works) Could someone explain
why I can not call length() method
This mistake:
pirma.cpp: In member function 'bool Aibe::isSubSet(const Aibe&)':
pirma.cpp:101: error: no matching function for call to 'Aibe::length()
const'
pirma.cpp:20: note: candidates are: int Aibe::length()

Some problem in using references
&nbsp(126 Views)
I wrote following code for insertion sort. The code was compiled using
gcc-4.1.1-30 on my fedora core 6 system. For this code output is not
correct {output is 2,5,76,76,76}. It seems, "line #2" is not working.
Meanwhile no problem occurs when
1. line #1 is changed to T key = arr[i]; or
2. line #2 is changed to T& q = arr[j+1]; q = key.
Am I missing something

A problem about concatenation in macro
&nbsp(111 Views)
I am just stumbled by a problem about concatenation in macro. See
below code snippet:
// there're some contants definition in this class
struct X
{
enum {A, B, C};
};
// and here I want to define a utility macro to help me generate some
functions
#define MK_FUNC(arg) \
int get##arg() \
{ \
return X::##arg; \
}
MK_FUNC(A)
MK_FUNC(B)
MK_FUNC(C)
#undef MKFUNC
// then I can use getA(), getB() .... in my program.
But the preprocessor always complains:
warning: pasting "::" and "A" does not give a valid preprocessing
token
warning: pasting "::" and "B" does not give a valid preprocessing
token
warning: pasting "::" and "C" does not give a valid preprocessing
token
I really don't why this will happen. Isn't this usage in the macro
"X::##arg" an invalid Hope someone can help me out.
- Martin

Design problem: Factory pattern needs 'static virtual'?
&nbsp(124 Views)
I need a simple object serialization, where loading an object from
file looks like this:
Foo* foo1 = FooFactory::create("./saved/foo1.a321f23d");
Foo* foo2 = FooFactory::create("./saved/foo2.eb287ac8");
Now, Foo is an abstract base class, and FooFactory contains a static
function which again calls static create functions on Foo1 or Foo2
(see code for all classes below). The problem is that all these
functions are static, but I also want them to be part of the (virtual)
Foo interface. But virtual static functions are not allowed.
You might say that Foo1::create(...) should not be a member function,
but just a global function outside of Foo1. But I want classes derived
from Foo1 to be able to inherit or override create(...).
How should I design this properly

DLL Entry point problem - Dll compiles but throws error when ran
&nbsp(163 Views)
I've written a simple dll in C++ which basically right now just consists of
a function to create an object, another function to check if an object has
been created or not, and finally a function to destroy the object. The
create, and Exists functions work fine, I added the destroy function and the
DLL was built fine, no errors, not even a warning. Then I tried to access
the destroy function of the dll and got this message
"The procedure entry point _myproject_Destroy could not be located in the
dynamic link library Mmyproject" (myproject substituted for the actual name
for privacy reasons). I recognize this as a standard Windows error message
when there's a dll problem but I can't figure out what it is.
Any ideas I'm accessing the destroy function the exact same way as the
create and exists function, I've double checked spelling and everything.