Thread View: comp.std.c++
3 messages
3 total messages
Started by Kevin McIsaac
Fri, 01 Dec 1995 00:10
const and typedefs, inconsistent?
Author: Kevin McIsaac
Date: Fri, 01 Dec 1995 00:10
Date: Fri, 01 Dec 1995 00:10
20 lines
1368 bytes
1368 bytes
A look at the April draft working papers at: http://www.cygnus.com/misc/wp/draft/dcl.html in section 7.1.2, shows the following examples: 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? And is it possible to format f(), using Pc, such that it resolves to const char*? TIA. -- // kev@lamsys.com // What the heck did you think it was made with? [ 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. ]
Re: const and typedefs, inconsistent?
Author: Kevin Lentin
Date: Mon, 04 Dec 1995 16:29
Date: Mon, 04 Dec 1995 16:29
24 lines
1889 bytes
1889 bytes
Kevin McIsaac (KevinM@lamsys.com) wrote: > > 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? And is it possible to format f(), using Pc, such that > it resolves to const char*? TIA. Because Pc is a pointer to char so const Pc should be a constant pointer to a char. This is written char* const. const char* is a pointer to a constant char which is something different. -- [=======================================================================] [ Kevin Lentin | The Mighty Carlton Blues | ] [ K.Lentin@cs.monash.edu.au | 1995 AFL Premiers | ] [ Macintrash: 'Just say NO!' |CARLTON 21-15-141 d geelong 11-14-80| ] [=======================================================================] [ 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. ]
Re: const and typedefs, inconsistent?
Author: Dick Menninger
Date: Mon, 04 Dec 1995 23:30
Date: Mon, 04 Dec 1995 23:30
50 lines
2128 bytes
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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads