* question about particular ptrmismatch warning
@ 2001-07-12 20:20 Tim Mooney
2001-07-13 17:50 ` ed.vogel
0 siblings, 1 reply; 3+ messages in thread
From: Tim Mooney @ 2001-07-12 20:20 UTC (permalink / raw)
Here's a chance for me to show how rusty I am at C. ;-)
Given the following (preprocessed) snippet, starting a function:
static int
foreachfile_callback (dirname, data1, data2)
char *dirname;
void * data1;
void * data2;
{
int (*func) ( const char * filename , void * data )
= (int (*) ( const char * filename , void * data ) ) data1;
When compiling this on Tru64 UNIX 5.1 with
Compaq C V6.3-028 on Compaq Tru64 UNIX V5.1 (Rev. 732)
Compiler Driver V6.3-026 (sys) cc Driver
and the following flags:
cc -DHAVE_CONFIG_H -I. -I. -I. -std1 -O2 -g3 -tune host -arch host -portable
-readonly_strings -msg_disable inlinestoclsmod,valuepres -c ltdl.c -DPIC
*why* does the compiler generate an Info message regarding the assignment
above (and subsequent Warning messages about ptrmismatch when func is
used later):
cc: Info: ltdl.c, line 2557: In the initializer for func, "data1" of type
"pointer to void", is being converted to "pointer to function (pointer to
const char, pointer to void) returning int". Such a cast is not permitted by
the standard. (nonstandcast)
= (int (*) LT_PARAMS((const char *filename, lt_ptr data))) data1;
-------------------------------------------------------------------^
It's nice that it says that `Such a cast is not permitted by the standard.',
but I'm left wondering what the real problem is. K&R2e has a bit of
vague verbiage on page 103 regarding, "...or even, except for void *, to
assign a pointer of one type to a pointer of another type without a cast."
Well, it *is* a void * that's being converted to a pointer to a function,
so it seems to be perfectly in line with what K&R2e says.
Is it spelled out more clearly in some subsequent standard (C89, or C9X)
why this is "not permitted by the standard"?
Thanks,
Tim
--
Tim Mooney mooney@dogbert.cc.ndsu.NoDak.edu
Information Technology Services (701) 231-1076 (Voice)
Room 242-J6, IACC Building (701) 231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: question about particular ptrmismatch warning
2001-07-12 20:20 question about particular ptrmismatch warning Tim Mooney
@ 2001-07-13 17:50 ` ed.vogel
2001-07-13 18:58 ` Tim Mooney
0 siblings, 1 reply; 3+ messages in thread
From: ed.vogel @ 2001-07-13 17:50 UTC (permalink / raw)
"Tim Mooney" <mooney@dogbert.cc.ndsu.NoDak.edu> wrote in message
news:9il0pr$6b8$1@news.ndsu.nodak.edu...
>
> cc -DHAVE_CONFIG_H -I. -I. -I. -std1 -O2 -g3 -tune host -arch
host -portable
> -readonly_strings -msg_disable inlinestoclsmod,valuepres -c ltdl.c -DPIC
>
> *why* does the compiler generate an Info message regarding the assignment
> above (and subsequent Warning messages about ptrmismatch when func is
> used later):
>
> cc: Info: ltdl.c, line 2557: In the initializer for func, "data1" of type
> "pointer to void", is being converted to "pointer to function (pointer to
> const char, pointer to void) returning int". Such a cast is not permitted
by
> the standard. (nonstandcast)
> = (int (*) LT_PARAMS((const char *filename, lt_ptr data))) data1;
> -------------------------------------------------------------------^
>
The compiler emits the message because you specified -portable on the
command line. This tells the compiler to emit diagnositics for
constructs
that may not be accepted by other compilers. Because this cast violates
the C standard, other compilers may not accept it.
> It's nice that it says that `Such a cast is not permitted by the
standard.',
> but I'm left wondering what the real problem is.
The standard only permits casts between pointers to object or incomplete
types and other pointers to object or incomplete types, or between
pointers
to function types. One can not cast a pointer to void (an incomplete
type) to a pointer to a
function type (as you are doing). I don't want to guess why the
standard
does not allow this. Maybe you could ask in comp.lang.c.
Note that if you would like more information on any compiler message,
add the -verbose switch to the command line. This will cause additional
information to be output for each message.
Hope this helps,
Ed Vogel
Compaq C Engineering.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: question about particular ptrmismatch warning
2001-07-13 17:50 ` ed.vogel
@ 2001-07-13 18:58 ` Tim Mooney
0 siblings, 0 replies; 3+ messages in thread
From: Tim Mooney @ 2001-07-13 18:58 UTC (permalink / raw)
In article <1yG37.698$rc5.47673@news.cpqcorp.net>,
<ed.vogel@compaq.com> wrote:
> "Tim Mooney" <mooney@dogbert.cc.ndsu.NoDak.edu> wrote in message
> news:9il0pr$6b8$1@news.ndsu.nodak.edu...
> >
> > cc -DHAVE_CONFIG_H -I. -I. -I. -std1 -O2 -g3 -tune host -arch
> host -portable
> > -readonly_strings -msg_disable inlinestoclsmod,valuepres -c ltdl.c -DPIC
> >
> > *why* does the compiler generate an Info message regarding the assignment
> > above (and subsequent Warning messages about ptrmismatch when func is
> > used later):
> >
> The compiler emits the message because you specified -portable on the
> command line. This tells the compiler to emit diagnositics for
> constructs that may not be accepted by other compilers. Because this
> cast violates the C standard, other compilers may not accept it.
Thanks. I did understand the what `-portable' was about, I was more
interested in why this wasn't considered portable, i.e. exactly why it
violates the standard.
> The standard only permits casts between pointers to object or incomplete
> types and other pointers to object or incomplete types, or between
> pointers to function types. One can not cast a pointer to void (an
> incomplete type) to a pointer to a function type (as you are doing). I
> don't want to guess why the standard does not allow this. Maybe you
> could ask in comp.lang.c.
:-) I thought about that, but I would definitely be showing my ignorance
in that group. It might be covered in the FAQ, though, so I'll take a look.
> Note that if you would like more information on any compiler message,
> add the -verbose switch to the command line. This will cause additional
> information to be output for each message.
>
> Hope this helps,
It does, thanks.
Tim
--
Tim Mooney mooney@dogbert.cc.ndsu.NoDak.edu
Information Technology Services (701) 231-1076 (Voice)
Room 242-J6, IACC Building (701) 231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-07-13 18:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-07-12 20:20 question about particular ptrmismatch warning Tim Mooney
2001-07-13 17:50 ` ed.vogel
2001-07-13 18:58 ` Tim Mooney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox