S
Stephan Schulz
Hi All,
I have a nice (and working) program that contains a NULL-terminated
array of function pointers:
static ClausePrioFun prio_fun_array[]=
{
PrioFunPreferGroundGoals,
PrioFunPreferUnitGroundGoals,
...
PrioFunPreferWatchlist,
PrioFunDeferWatchlist,
NULL
};
....where ClausePrioFun is defined as
typedef EvalPriority (*ClausePrioFun)(Clause_p clause);
and all the other types are well-defined as well.
The program has compiled (and worked) fine for years on a large number
of OS/Compiler combinations.
Now it is being ported much more widely, and one compiler (that I do
not have direct access to) reports
/opt-ext/studio90.d/SUNWspro/bin/cc -c -o che_prio_funs.o
-O -xarch=v9 -DNDEBUG -DCONSTANT_MEM_ESTIMATE -DFAST_EXIT
che_prio_funs.c
"che_prio_funs.c", line 100: warning: initialization type mismatch
where line 100 is the line with the NULL above.
Now, I suspect that NULL is defined as ((void*)0) on that platform,
and I know that void* is not guranteed to be auto-castable to a
function pointer type. My suspicion is that that causes the warning.
However, I wonder if there is a portable, standard way to get the
function pointer equivalent of NULL, i.e. a pointer that is considered
as logically false in if(),&&,||,!, and that is different from all
pointers that point somewhere sensible.
My first guess would be to just use 0, the second to explicitely cast
0 or NULL to ClausePrioFun.
Neither is totally convincing. I checked the FAQ, but either was blind
or it does not contain anything useful.
I'm thankful for any help...
Bye,
Stephan
I have a nice (and working) program that contains a NULL-terminated
array of function pointers:
static ClausePrioFun prio_fun_array[]=
{
PrioFunPreferGroundGoals,
PrioFunPreferUnitGroundGoals,
...
PrioFunPreferWatchlist,
PrioFunDeferWatchlist,
NULL
};
....where ClausePrioFun is defined as
typedef EvalPriority (*ClausePrioFun)(Clause_p clause);
and all the other types are well-defined as well.
The program has compiled (and worked) fine for years on a large number
of OS/Compiler combinations.
Now it is being ported much more widely, and one compiler (that I do
not have direct access to) reports
/opt-ext/studio90.d/SUNWspro/bin/cc -c -o che_prio_funs.o
-O -xarch=v9 -DNDEBUG -DCONSTANT_MEM_ESTIMATE -DFAST_EXIT
che_prio_funs.c
"che_prio_funs.c", line 100: warning: initialization type mismatch
where line 100 is the line with the NULL above.
Now, I suspect that NULL is defined as ((void*)0) on that platform,
and I know that void* is not guranteed to be auto-castable to a
function pointer type. My suspicion is that that causes the warning.
However, I wonder if there is a portable, standard way to get the
function pointer equivalent of NULL, i.e. a pointer that is considered
as logically false in if(),&&,||,!, and that is different from all
pointers that point somewhere sensible.
My first guess would be to just use 0, the second to explicitely cast
0 or NULL to ClausePrioFun.
Neither is totally convincing. I checked the FAQ, but either was blind
or it does not contain anything useful.
I'm thankful for any help...
Bye,
Stephan