🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #42570

Problem with const pointer parameters and typedef

#42570
From: Phillip Drury
Date: Sun, 26 Nov 1995 00:00
49 lines
2227 bytes
I have come across this interesting problem with const pointer parameters
and typedefs and was wondering if anybody could explain it to me. I have
compiled the following code with gcc 2.6.3 and the Sun cc 3.0.1 compiler
and both have given the same result.

typedef int *pINT;

void
Test(int* param)
	{
	}

void
Func1(const int* param)
	{				
	Test(param); /* Compiler complains const int* passed to int* parameter */
	}

Func2(const pINT param)
	{
	Test(param); /* Compiler does not complain */
	}

Now can anyone explain to me why the compiler does not complain about
the second case because "const int* param" should be exactly the same
as "const pINT param" as there exists the typedef int *pINT.

Reading from the ANSI draft standard 31 October 1988 (OK its the latest I
can lay my hands on) it states in section A8.9

    "A typedef declaration attributes a type to each name among its
	 declarators in the usual way. Thereafter, each such typedef name
	 is syntactically equivalent to a type specifier keyword for the
	 associated type"

This statement leads me to believe that the above behaviour exhibited by
these two compilers is wrong.

So what is the story. Is this a compiler bug or am I missing something
and if so what is the fix. I do not wish to resort to #define pINT *int,
if I can at all avoid it.

Thanks

-----------------------------------------------------------------------
| Phillip Drury.             |                                        |
| SBC Warburg Australia Ltd. | Internet   : pld@syd.au.swissbank.com  |
| Sydney Australia.          | NeXT Email : drury@il.us.swissbank.com |
-----------------------------------------------------------------------
Technical Details
Message-ID: <gnusenet1995Nov23.012520.24896@il.us.swissbank.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,17d5a0531f394683
X-Google-Attributes: gid11318c,public
From: pld@syd.AU.swissbank.COM (Phillip Drury)
Subject: Problem with const pointer parameters and typedef
Date: 1995/11/26
Message-ID: <gnusenet1995Nov23.012520.24896@il.us.swissbank.com>
X-Deja-AN: 120166881
distribution: gnu
sender: daemon@cis.ohio-state.edu
organization: SBC Warburg Australia
reply-to: pld@syd.au.swissbank.com
newsgroups: gnu.gcc.help