🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2841

Re: const and typedefs, inconsistent?

#2841
From: Dick Menninger
Date: Mon, 04 Dec 1995 23:30
50 lines
2128 bytes

> ==========Kevin McIsaac, 11/30/95==========
 
>   typedef char* Pc;
>   void f(const Pc);       // void f(char* const)  (not const char*)
>   void g(const int Pc);   // void g(const int)
 
> May questions are: why the f(const Pc) resolves to char* const? Is the 
> associativity changed?

I look at it this way:
The normal interpretation of const char * is as if
you wrote (const char)* instead.
But when you said:
typedef char* Pc;
you, in effect, put in parantheses as: (char *)
for any use of Pc.
A typedef is indivisible as it is now a type and
char * is just the meaning of the type.
It is like asking how you break an int into two parts.
So const can only apply to it as an indivisible unit.
As a result, const PC is the same as Pc const.

This is actually the feature a typedef provides
in setting up complicated meanings correctly.
If you nibble at it in small enough pieces,
order is less important and it is harder to mess
up the parentheses (once you understand).
Some examples involve pointers to functions that
return messy pointers to functions.  A sequence
of typedefs is a good way to get it right, and later
to determine what it is you got right.  You might
even avoid a headache from it.

> And is it possible to format f(), using
> Pc, such that it resolves to const char*? TIA.

There is no way.

Good Day
Dick
Dick.Menninger@DaytonOH.ATTGIS.COM



---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <DJ32pC.2oE@falcon.daytonoh.attgis.com>
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt
References: <49ler5$qgu@shadow2.qnetix.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt
From: Dick Menninger <Dick.Menninger@daytonoh.attgis.com>
Newsgroups: comp.std.c++
Subject: Re: const and typedefs, inconsistent?
Date: 04 Dec 1995 23:30:20 GMT
Organization: AT&T Global Information Solutions
Approved: Matt@Austern
Message-ID: <DJ32pC.2oE@falcon.daytonoh.attgis.com>
References: <49ler5$qgu@shadow2.qnetix.ca>
Reply-To: mennid <Dick.Menninger@daytonoh.attgis.com>
NNTP-Posting-Host: austern.hip.berkeley.edu