From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20536 invoked by alias); 14 Aug 2009 13:12:27 -0000 Received: (qmail 20470 invoked by uid 22791); 14 Aug 2009 13:12:26 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from smtp22.services.sfr.fr (HELO smtp22.services.sfr.fr) (93.17.128.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 14 Aug 2009 13:12:19 +0000 Received: from filter.sfr.fr (localhost [127.0.0.1]) by msfrf2203.sfr.fr (SMTP Server) with ESMTP id 8B02B7000084 for ; Fri, 14 Aug 2009 15:12:16 +0200 (CEST) Received: from [223.200.200.20] (130.138.84-79.rev.gaoland.net [79.84.138.130]) by msfrf2203.sfr.fr (SMTP Server) with ESMTP id 60F4B7000081 for ; Fri, 14 Aug 2009 15:12:16 +0200 (CEST) X-SFR-UUID: 20090814131216397.60F4B7000081@msfrf2203.sfr.fr Message-ID: <4A8562B2.7020608@free.fr> Date: Fri, 14 Aug 2009 17:28:00 -0000 From: Marc Mason Reply-To: gcc@gcc.gnu.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.22) Gecko/20090605 SeaMonkey/1.1.17 MIME-Version: 1.0 To: gcc@gcc.gnu.org Subject: (int *const) function parameter Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2009-08/txt/msg00237.txt.bz2 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: 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.