www.digitalmars.com         C & C++   DMDScript  

c++.dos - problem with const keyword in casting

reply Benoit <Benoit_member pathlink.com> writes:
Hi,
I am trying to compile the watt-32 library with digital mars. I got only 4 files
that wasn't compiled by digital mars. I was unable to fix the compilation errror
and think now that it is an issue with de digital mars compiler.

Here is the error ouput of the first file:

c:\djgpp\bin\dmc -ml -a2 -I. -I..\inc -IC:\dm\include -W -fno-strength-reduce -f
fast-math  -o digmars/misc.o -c misc.c
misc.c:
((int(far *)(void const const *, void const const *))list_compare));
^
misc.c(463) : Error: need explicit cast for function parameter 4 to get
from: int (*far C func)(void *,void *)
to  : int (*far C func)(void const *,void const *)
--- errorlevel 1
make.exe: *** [digmars/misc.o] Error 1

C:\net\watt\src>

The cast is exactly as requested by the compiler. I try all sort of variation
and I am unable to please digital mars. I feel that digital mars have some
difficulty with the "const" keyword.

I got similar error with 3 other files.

Ex.: char const var instead of const char var
Ex.:
from: int (*far C func)(void *,void *)
to  : int (*far C func)(void const *,void const *)

the from: line is no having the const keywork but the cast into the line of C++
code is having the const keyword. That's why digitial mars see and not see the
const keyword.

thank you

Benoit
Oct 13 2004
parent reply Arjan Knepper <arjan ask.me> writes:
Benoit wrote:
 c:\djgpp\bin\dmc -ml -a2 -I. -I..\inc -IC:\dm\include -W -fno-strength-reduce
-f
 fast-math  -o digmars/misc.o -c misc.c
 misc.c:
 ((int(far *)(void const const *, void const const *))list_compare));
 ^
 misc.c(463) : Error: need explicit cast for function parameter 4 to get
 from: int (*far C func)(void *,void *)
 to  : int (*far C func)(void const *,void const *)
 --- errorlevel 1
 make.exe: *** [digmars/misc.o] Error 1
Can you post the lines 460-465 from misc.c? Because that is the code the compiler is complaining about. Arjan
Oct 14 2004
parent reply Benoit <Benoit_member pathlink.com> writes:
HI, the lines are:

qsort (&exit_list, DIM(exit_list), sizeof(exit_list[0]),
(int(*)(const void *, const void *))list_compare);

Benoit

In article <cklh3d$1tsl$1 digitaldaemon.com>, Arjan Knepper says...
Benoit wrote:
 c:\djgpp\bin\dmc -ml -a2 -I. -I..\inc -IC:\dm\include -W -fno-strength-reduce
-f
 fast-math  -o digmars/misc.o -c misc.c
 misc.c:
 ((int(far *)(void const const *, void const const *))list_compare));
 ^
 misc.c(463) : Error: need explicit cast for function parameter 4 to get
 from: int (*far C func)(void *,void *)
 to  : int (*far C func)(void const *,void const *)
 --- errorlevel 1
 make.exe: *** [digmars/misc.o] Error 1
Can you post the lines 460-465 from misc.c? Because that is the code the compiler is complaining about. Arjan
Oct 15 2004
parent Arjan Knepper <arjan ask.me> writes:
Benoit wrote:
 HI, the lines are:
 
 qsort (&exit_list, DIM(exit_list), sizeof(exit_list[0]),
 (int(*)(const void *, const void *))list_compare);
 
I don't see why this would not work assuming the other function parameters are correct. To work around this, you could try to wrap 'list_compare' in a function with the exact signature required by qsort. e.g. int qsort_wrap ( const void *_f, const void *_s ) { return ( list_compare ( (cast) _f, (cast) _s ) ); } Arjan
 Benoit
 
 In article <cklh3d$1tsl$1 digitaldaemon.com>, Arjan Knepper says...
 
Benoit wrote:

c:\djgpp\bin\dmc -ml -a2 -I. -I..\inc -IC:\dm\include -W -fno-strength-reduce -f
fast-math  -o digmars/misc.o -c misc.c
misc.c:
((int(far *)(void const const *, void const const *))list_compare));
^
misc.c(463) : Error: need explicit cast for function parameter 4 to get
from: int (*far C func)(void *,void *)
to  : int (*far C func)(void const *,void const *)
--- errorlevel 1
make.exe: *** [digmars/misc.o] Error 1
Can you post the lines 460-465 from misc.c? Because that is the code the compiler is complaining about. Arjan
Oct 18 2004