🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #42568

Re: Problem with const pointer parameters and typedef

#42568
From: Ken Walter
Date: Sun, 26 Nov 1995 00:00
39 lines
1536 bytes
In message <1995Nov23.012520.24896@il.us.swissbank.com> - pld@syd.au.swissbank.
com (Phillip Drury) writes:
:>
:>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.
:>

No, they are not the same!  a typedef is like an implied parentheses.

const pINT == const (int*) == int * const.

Ken Walter

* All the above is hearsay and the opinion of nobody in particular
Technical Details
Message-ID: <gnusenet491v1u$qe8@news.gate.net>
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,start
X-Google-Attributes: gid11318c,public
From: solution@gate.net (Ken Walter)
Subject: Re: Problem with const pointer parameters and typedef
Date: 1995/11/26
Message-ID: <gnusenet491v1u$qe8@news.gate.net>
X-Deja-AN: 120166879
distribution: gnu
sender: daemon@cis.ohio-state.edu
organization: Solution Technology
newsgroups: gnu.gcc.help