Stack overflow: Correct way to define a pointer to a function?

  • Thread starter Thread starter Willy Denoyette [MVP]
  • Start date Start date
W

Willy Denoyette [MVP]

RalphTheExpert said:
method

Actually, neither. I'm talking about a C++ (isn't this a C++ forum?)
pointer to a vanilla static function.

Unfortunately, I don't know C# and can't tell exactly what you are
doing.

What JAL shows you is not C#, it is a (VS2005) C++/CLI code snip, probably
he got confused by this
<Under MC++, what is ...>, means... Under Managed C++ (VS2002/2003).

Willy.
 
Under MC++, what is the right way to define a (typedef'd) pointer to a
static function?

When I call a function through a pointer I get a stack overflow.


For those having the same problem, I worked around the problem by
replacing the pointer to a function with a functor.

If you need to know what a functor is, just ask.

Ralph Shnlevar
 
Ralph.... Are you asking about a delegate or type safe pointer to a method
call:

public ref class Program {
public :
static void StaticMethod(int i) {
Console::WriteLine(i);
}
};
public delegate void SomeDelegate(int i);

int main(array<System::String ^> ^args)
{
SomeDelegate^ del= gcnew SomeDelegate(&Program::StaticMethod);
del(5);
Console::ReadLine();
return 0;
}
 
JAL said:
Ralph.... Are you asking about a delegate or type safe pointer to a
method

Actually, neither. I'm talking about a C++ (isn't this a C++ forum?)
pointer to a vanilla static function.

Unfortunately, I don't know C# and can't tell exactly what you are
doing.
 
Hi Ralph... Well. I'm afraid the code i posted is a form of C++, MC++, or
managed C++ in this the dotnet newsgroup :)
 
When I call a function through a pointer I get a stack overflow.A stack overflow is typically caused by calling a function recursively.
or if A calls B calls C calls A calls B calls C calls A Calls B calls C
<crash...>

My guess is that you have some (hidden) loop in your code that keeps calling
in a call in a call in a call...
 
Olaf Baeyens said:
My guess is that you have some (hidden) loop in your code that keeps calling
in a call in a call in a call...

Nope. The problem happens immediately when I attempt to step into the
function being called.

The stack overflow is just one of several crash symptoms.


I don't understand MC++ at all well. I can truly understand why Carl
Daniel said in Message-ID: <[email protected]>,

"Managed Extensions for C++ are a collection of syntax and semantic
extensions to C++ supported by VC++ 2002 (7.0) and later. This is a
fully ISO conforming extension, using lots of ugly __prefixed names for
new features. Managed extensions doesn't expose everything that the .NET
platform has to offer and has not been very well accepted."


I read somewhere (I think) that MC++ does not support pointers to
functions. This would make a certain amount of sense since it might
confuse the garbage colector.

Like I said, I don't understand MC++ at all. I have to use MC++ 2003
because it was specified in the contract I have but, ugh, it is ugly.

I do like (a lot) the "object orientation" of the .Net environment. But
slapping try/catch/finally and a lack of being able to put managed
objects on the stack and being unable to declare friends in public __gc
classes, etc., is just, well, awful.

Ralph
 
RalphTheExpert said:
I don't understand MC++ at all well. I can truly understand why Carl
Daniel said in Message-ID: <[email protected]>,

"Managed Extensions for C++ are a collection of syntax and semantic
extensions to C++ supported by VC++ 2002 (7.0) and later. This is a
fully ISO conforming extension, using lots of ugly __prefixed names for
new features. Managed extensions doesn't expose everything that the .NET
platform has to offer and has not been very well accepted."


I read somewhere (I think) that MC++ does not support pointers to
functions. This would make a certain amount of sense since it might
confuse the garbage colector.

Like I said, I don't understand MC++ at all. I have to use MC++ 2003
because it was specified in the contract I have but, ugh, it is ugly.

I do like (a lot) the "object orientation" of the .Net environment. But
slapping try/catch/finally and a lack of being able to put managed
objects on the stack and being unable to declare friends in public __gc
classes, etc., is just, well, awful.

Ralph:

Can you switch to Visual Studio 2005? There MC++ is replaced by a new
language, C++/CLI, with a much more pleasant syntax, and some real
improvments like automatic deterministic destruction. The old MC++
syntax still works, but is deprecated. An automatic translator was
"promised", but has not materialized. Visual C++ Express is free.

David Wilkinson
 
Nope. The problem happens immediately when I attempt to step into the
function being called.

The stack overflow is just one of several crash symptoms.
In my case it is because it is because in the function I call myself
accidentially.

Allocating too big of local memory could also cause a stack overflow.
For example a huge array. Better to allocate using a 'new' in that case.
 
(isn't this a C++ forum?)

Not exactly. It's a C forum specializing in VS.NET as a development
platform. This includes both C++ and C#, and even 'vanilla' C. So responses
in C# are valid unless you specify what language you're interested in (and
C# translates to C++ with not too much difficulty)... : )

[==P==]
 
Back
Top