[phpBB Debug] PHP Warning: in file /s3vol/www/scitools.com/html/includes/lib/function.basic.php on line 159: Missing argument 1 for isMeteonicCountry(), called in /s3vol/www/scitools.com/html/includes/navbarForum.inc.php on line 48 and defined
[phpBB Debug] PHP Warning: in file /s3vol/www/scitools.com/html/includes/lib/function.basic.php on line 146: Missing argument 1 for isEmendaCountry(), called in /s3vol/www/scitools.com/html/includes/navbarForum.inc.php on line 48 and defined

Forum

Problem with Function Pointer Parameters in Hdr

Ask questions and find out more about using Understand.

Postby willrich » Tue Feb 28, 2012 1:54 am

Greetings all, I've been trying to resolve the following problem (reduced to its simplest possible form) in which Und sees the declaration in the hdr file as a 'global object' which does not link to the definition in the code file:

Code: Select all
****************************************************
// Test.h

int initCallBack(int (*callBack)(int cmd));

****************************************************
// Test.cpp

#include "Test.h"

int (*callBackP)(int cmd);

// initialize callback
int initCallBack(int (*callBack)(int cmd)) {
   callBackP = callBack;
   return 0;
   }

****************************************************

However, I was able to get it to work correctly by prepending 'extern' to the hdr declaration. I guess my question now is, is this 'expected' behaviour by Und or am I still missing something? It's no big deal but I like things as simple as possible + none of my other hdr decs require 'extern'.

Thanks, Will.
willrich
 
Posts: 2
Joined: Sun Feb 26, 2012 10:34 pm

Postby KevinG » Tue Feb 28, 2012 3:51 am

Hi Will,
I'll check with the engineers on this.
Regards,
KevinG
User avatar
KevinG
 
Posts: 256
Joined: Tue Apr 27, 2010 11:11 pm
Location: St George, Utah

Postby KevinG » Tue Feb 28, 2012 5:59 am

I heard back from the engineer on this, it looks like the strict analyzer handles this correctly. This looks like an example of the so-called "most vexing parse" (http://en.wikipedia.org/wiki/Most_vexing_parse). I think that the best way to work around this in the flexible analyzer, without adding something like extern, is to typedef the function pointer type and use that as the parameter type instead.
Regards,
KevinG
User avatar
KevinG
 
Posts: 256
Joined: Tue Apr 27, 2010 11:11 pm
Location: St George, Utah

Postby willrich » Tue Feb 28, 2012 6:28 pm

Thanks Kevin. While the strict analyzer option did work, I'm not willing to give up the rapidity of the 'fuzzy' parser. I ended up going with the function pointer typedef as you suggested which worked great. Thanks again for your help.

Will
willrich
 
Posts: 2
Joined: Sun Feb 26, 2012 10:34 pm


Return to Understand Q&A

Who is online

Users browsing this forum: No registered users and 1 guest