Article View: gnu.gcc.help
Article #42571Re: Problem with const pointer parameters and typedef
From: Tanmoy Bhattacharya
Date: Sun, 26 Nov 1995 00:00
Date: Sun, 26 Nov 1995 00:00
60 lines
2823 bytes
2823 bytes
In article <1995Nov23.012520.24896@il.us.swissbank.com>, pld@syd.au.swissbank.com (Phillip Drury) writes: <snip> |> 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. repeat a million times: `typedef is not a macro'!!! typedef int *pINT defines pINT to be a _pointer_ to int. It is a kind of pointer _not_ a kind of int. const pINT is therefore a pointer that is a constant. const int* is a (non-constant) pointer to a constant int. So, const pINT is _not_ const int*. |> |> 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" |> Read again. a typedef name is syntactically equivalent to a _type specifier keyword_ that specifies the type. It is not syntactically equivalent to the string of tokens used to declare it. |> This statement leads me to believe that the above behaviour exhibited by |> these two compilers is wrong. No: you misunderstood. |> |> 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. #define pINT *int is a bit hard to use anyway :-) Given typedef int *pINT, there is no way to derive const int * from pINT. const int * is a _very_ different object from int * there is no reason why you should be able to get one from the other. Cheers Tanmoy -- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242) Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544 Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>, <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/ internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html> fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
Technical Details
Message-ID:
<gnusenet4913ri$7kf@newshost.lanl.gov>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<1995Nov23.012520.24896@il.us.swissbank.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,17d5a0531f394683 X-Google-Attributes: gid11318c,public From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) Subject: Re: Problem with const pointer parameters and typedef Date: 1995/11/26 Message-ID: <gnusenet4913ri$7kf@newshost.lanl.gov> X-Deja-AN: 120166882 distribution: gnu sender: daemon@cis.ohio-state.edu references: <1995Nov23.012520.24896@il.us.swissbank.com> organization: Los Alamos National Laboratory newsgroups: gnu.gcc.help