Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RalphTheExpert - 19 Nov 2005 14:21 GMT
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
JAL - 19 Nov 2005 22:39 GMT
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;
}

> Under MC++, what is the right way to define a (typedef'd) pointer to a
> static function?
[quoted text clipped - 7 lines]
>
> Ralph Shnlevar
RalphTheExpert - 19 Nov 2005 23:16 GMT
>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.

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Willy Denoyette [MVP] - 19 Nov 2005 00:06 GMT
>>Ralph.... Are you asking about a delegate or type safe pointer to a
> method
[quoted text clipped - 8 lines]
> Sent via .NET Newsgroups
> http://www.dotnetnewsgroups.com

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.
JAL - 20 Nov 2005 00:08 GMT
Hi Ralph... Well. I'm afraid the code i posted is a form of C++, MC++, or
managed C++ in this the dotnet newsgroup :)

> >Ralph.... Are you asking about a delegate or type safe pointer to a
> method
[quoted text clipped - 8 lines]
> Sent via .NET Newsgroups
> http://www.dotnetnewsgroups.com
Peter Oliphant - 22 Nov 2005 18:36 GMT
>(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==]

>>Ralph.... Are you asking about a delegate or type safe pointer to a
> method
[quoted text clipped - 8 lines]
> Sent via .NET Newsgroups
> http://www.dotnetnewsgroups.com 
Olaf Baeyens - 22 Nov 2005 09:04 GMT
> 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...
RalphTheExpert - 22 Nov 2005 11:21 GMT
>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: <Os7Fnbi7FHA.2816@tk2msftngp13.phx.gbl>,

"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

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
David Wilkinson - 22 Nov 2005 11:41 GMT
> I don't understand MC++ at all well.  I can truly understand why Carl
> Daniel said in Message-ID: <Os7Fnbi7FHA.2816@tk2msftngp13.phx.gbl>,
[quoted text clipped - 16 lines]
> 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
Olaf Baeyens - 22 Nov 2005 12:21 GMT
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.