public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* (int *const) function parameter
@ 2009-08-14 17:28 Marc Mason
  2009-08-14 17:40 ` Joseph S. Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Marc Mason @ 2009-08-14 17:28 UTC (permalink / raw)
  To: gcc

Hello,

The following code is rejected by one compiler, while it is accepted by gcc
without any warning. Several people in comp.lang.c seem to think that it is a
bug in the first compiler which should ***not*** reject the program.

Message-ID: <h63e5s$ecu$1@aioe.org>
http://groups.google.com/group/comp.lang.c/browse_frm/thread/2858a1c9ccdcd741

I'd like to ask what you think.

typedef int fun_t(int *p);

int foo1(      int *      p) { return *p; }
int foo2(const int *      p) { return *p; }
int foo3(      int *const p) { return *p; }
int foo4(const int *const p) { return *p; }

void zozo(void)
{
  fun_t *fp;
  fp = foo1;
  fp = foo2; /* GCC WARNS */
  fp = foo3;
  fp = foo4; /* GCC WARNS */
}

(I run gcc 4.3.2 under cygwin.)

$ gcc -std=c89 -pedantic -Wall -Wextra -O2 -c mu2.c
mu2.c: In function 'zozo':
mu2.c:12: warning: assignment from incompatible pointer type
mu2.c:14: warning: assignment from incompatible pointer type

$ cc -c mu2.c
E "mu2.c",L12/C8(#416): foo2
|    Type `int(const int * p)' ("mu2.c",L4/C5) can't be converted to type
`fun_t(*)'.
|    (See also type `fun_t' (= `int(int * p)') ("mu2.c",L1/C13)).
E "mu2.c",L13/C8(#416): foo3
|    Type `int(int *const p)' ("mu2.c",L5/C5) can't be converted to type `fun_t(*)'.
|    (See also type `fun_t' (= `int(int * p)') ("mu2.c",L1/C13)).
E "mu2.c",L14/C8(#416): foo4
|    Type `int(const int *const p)' ("mu2.c",L6/C5) can't be converted to type
`fun_t(*)'.
|    (See also type `fun_t' (= `int(int * p)') ("mu2.c",L1/C13)).
3 user errors   No warnings

The relevant line is line 13 i.e. fp = foo3;
(cc's warnings are cosmetically different if I write fp = &foo3;)

E "mu2.c",L13/C8(#416):
|    Type `int(*)(int *const p)' can't be converted to type `fun_t(*)'.
|    (See also type `int(int *const p)' ("mu2.c",L5/C5)).
|    (See also type `fun_t' (= `int(int * p)') ("mu2.c",L1/C13)).

In short, cc refuses to convert
an "int (*)(int *const)" pointer to an "int (*)(int *)" pointer.

Would you say this is a bug in cc?

-- 
Regards.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: (int *const) function parameter
  2009-08-14 17:28 (int *const) function parameter Marc Mason
@ 2009-08-14 17:40 ` Joseph S. Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph S. Myers @ 2009-08-14 17:40 UTC (permalink / raw)
  To: gcc

On Fri, 14 Aug 2009, Marc Mason wrote:

> Hello,
> 
> The following code is rejected by one compiler, while it is accepted by gcc
> without any warning. Several people in comp.lang.c seem to think that it is a
> bug in the first compiler which should ***not*** reject the program.
> 
> Message-ID: <h63e5s$ecu$1@aioe.org>
> http://groups.google.com/group/comp.lang.c/browse_frm/thread/2858a1c9ccdcd741
> 
> I'd like to ask what you think.

Bugs in other compilers are offtopic for this list.  The relevant wording 
from 6.7.5.3#15 has already been quoted in that discussion.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-08-14 14:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-14 17:28 (int *const) function parameter Marc Mason
2009-08-14 17:40 ` Joseph S. Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).