Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Function pointers generate parentheses
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

znakeeye
Tomato Guru

379 Posts

Posted - Jul 17 2007 :  10:59:24 AM  Show Profile  Reply with Quote
Hi,

Have had problems with this, since early versions. Was too lazy to complain :).

void LoadLibrary() // Parentheses expected on declaration
LoadLibrary() // Parentheses expected on call
pfnLoadLibrary = &LoadLibrary() // Parentheses NOT expected
pfnLoadLibrary = &CMyClass::LoadLibrary() // Parentheses NOT expected


Function pointers are traditionally not used on a regular basis, but if using template libraries such as Boost, they are indeed quite common.

IDE = VS 2005 SP1
VAX = 10.3.1557

feline
Whole Tomato Software

United Kingdom
18934 Posts

Posted - Jul 17 2007 :  3:05:57 PM  Show Profile  Reply with Quote
At the risk of playing devils advocate, what if you had been trying to write:

pfnLoadLibrary = &LoadLibrary()->nMember;


You do make an interesting point, I am just wondering if there is a valid argument in favour of what VA is currently doing.

zen is the art of being at one with the two'ness
Go to Top of Page

znakeeye
Tomato Guru

379 Posts

Posted - Jul 18 2007 :  01:37:19 AM  Show Profile  Reply with Quote
Good point indeed. Now I had to think a bit :-)
Anyway, your above code is not always valid. Also, the assignment statement is important.

The parentheses are never wanted if:
1) If the function does not return a referrable object.
I.e. basic types: void, int, char, ... Also (just checked): int*, char*, ...

2) If the function is a non-static class member.
E.g.
struct CFoo { CFoo foo() { return CFoo(); } };
pfnFoo = &CFoo::foo() // invalid, since foo is non-static

3) If the lvalue is a function pointer. Not sure if VAX has support for such type-checking...
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18934 Posts

Posted - Jul 18 2007 :  06:41:30 AM  Show Profile  Reply with Quote
I am very wary of trying to get "clever", by running this many checks. One reason is simply that the behaviour stops being "simple".

While the behaviour, and rules behind it are simple they can be explained, tested, and people know what to expect. But complex behaviour is much harder to explain and support.

VA should know if a given class member function is a function pointer or not, so I am inclined towards an "all or nothing" approach here.

Also what happens when you are calling this function pointer / function? It has been a while since I did much work with function pointers (good old C ) but my memory was that I spent more time calling them than I did setting them.

zen is the art of being at one with the two'ness
Go to Top of Page

znakeeye
Tomato Guru

379 Posts

Posted - Jul 20 2007 :  03:09:44 AM  Show Profile  Reply with Quote
I see your point. So let's look at the simple approach then.
How often do you find yourself typing this?
&SomeFunction();

I know I haven't done that - ever. There are two reasons:
1) You simply don't write *Foo() or &Foo(). Look through your source code. You won't find many of them ;)
2) If the programmer insists, he will most likely add the prefix after typing 'SomeFunction()'. "Oh, I need a pointer..."
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18934 Posts

Posted - Jul 20 2007 :  07:33:18 AM  Show Profile  Reply with Quote
It took a few moments, but I did think of a case:

std::string &CMyClass::returnsAReference()
{
    // body
}

Having said that, this seems a sensible change, and it should cause very few problems, if any, so long as VA can reliably distinguish between these two situations. I have put in a feature request for this:

case=7802

zen is the art of being at one with the two'ness
Go to Top of Page

sean
Whole Tomato Software

USA
2817 Posts

Posted - Jun 12 2009 :  9:03:05 PM  Show Profile  Reply with Quote
case=7802 is fixed in build 1727
Go to Top of Page

support
Whole Tomato Software

5566 Posts

Posted - Aug 22 2009 :  7:19:47 PM  Show Profile  Reply with Quote
There was an additional problem with case=7802 when namespaces were present. This is fixed in build 1731.

Whole Tomato Software, Inc.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000