N
Noob
Hello,
Consider the following program.
typedef int fun_t(int *const pTask, void *pContext);
typedef fun_t *tTaskCode;
int foo1(int *const pTask, void *const pParam) { return 1; }
int foo2(int *const pTask, void * pParam) { return 2; }
void zozo(void)
{
tTaskCode pTaskCode;
pTaskCode = foo1; /*** PROBLEM HERE ***/
pTaskCode = foo2;
}
gcc 4.3.2 seems happy with it.
$ gcc -O2 -std=c89 -Wall -Wextra -pedantic -Wno-unused -c mu2.c
/* NO OUTPUT */
but this other compiler rejects it.
$ cc -c mu2.c
E "mu2.c",L10/C15(#416):
foo1 Type `int(int *const pTask, void *const pParam)' ("mu2.c",L4/C5)
can't be converted to type `tTaskCode'
(= `int(*)(int *const pTask, void * pContext)') ("mu2.c",L2/C16).
1 user error No warnings
The 2nd param to fun_t is void *
while the 2nd param to foo1 is void *const
I assume these two types are incompatible?
Is there some constraint violation? (I assume yes.)
Is a conforming compiler allowed to refuse the code?
Is a conforming compiler required to refuse the code?
I'm generally confused about the usefulness of "thing *const p" function
parameters, which disallow code from modifying p (not the memory pointed
to by p). The "thing *const" types seem rather useless to me, as function
parameters. The function is getting a private copy of the pointer anyway.
void foob(char *const p)
{
/* p++ not allowed, use a temp var to copy p */
}
I'd drop the const, and increment p if I need to, instead of using a temp variable.
Or did I miss something important?
Regards.
Consider the following program.
typedef int fun_t(int *const pTask, void *pContext);
typedef fun_t *tTaskCode;
int foo1(int *const pTask, void *const pParam) { return 1; }
int foo2(int *const pTask, void * pParam) { return 2; }
void zozo(void)
{
tTaskCode pTaskCode;
pTaskCode = foo1; /*** PROBLEM HERE ***/
pTaskCode = foo2;
}
gcc 4.3.2 seems happy with it.
$ gcc -O2 -std=c89 -Wall -Wextra -pedantic -Wno-unused -c mu2.c
/* NO OUTPUT */
but this other compiler rejects it.
$ cc -c mu2.c
E "mu2.c",L10/C15(#416):
foo1 Type `int(int *const pTask, void *const pParam)' ("mu2.c",L4/C5)
can't be converted to type `tTaskCode'
(= `int(*)(int *const pTask, void * pContext)') ("mu2.c",L2/C16).
1 user error No warnings
The 2nd param to fun_t is void *
while the 2nd param to foo1 is void *const
I assume these two types are incompatible?
Is there some constraint violation? (I assume yes.)
Is a conforming compiler allowed to refuse the code?
Is a conforming compiler required to refuse the code?
I'm generally confused about the usefulness of "thing *const p" function
parameters, which disallow code from modifying p (not the memory pointed
to by p). The "thing *const" types seem rather useless to me, as function
parameters. The function is getting a private copy of the pointer anyway.
void foob(char *const p)
{
/* p++ not allowed, use a temp var to copy p */
}
I'd drop the const, and increment p if I need to, instead of using a temp variable.
Or did I miss something important?
Regards.