473,624 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

const in function declarations

What do each of these mean? Thanks. I am incredibly confused.

char foo (const char * &p );
char foo (const char &* p );
char foo (const &char * p );

char foo (const char * const &p );
char foo (const char * &const p );
char foo (const char &* const p );
char foo (const &char * const p );

char foo (const& char * const &p );
char foo (const& char * &const p );
char foo (const& char &* const p );
char foo (const& char * const p );

char foo (const char& * const &p );
char foo (const char& * &const p );

Jul 23 '05 #1
5 2152

TechCrazy wrote:
What do each of these mean? Thanks. I am incredibly confused.

char foo (const char * &p );
char foo (const char &* p );
char foo (const &char * p );

char foo (const char * const &p );
char foo (const char * &const p );
char foo (const char &* const p );
char foo (const &char * const p );

char foo (const& char * const &p );
char foo (const& char * &const p );
char foo (const& char &* const p );
char foo (const& char * const p );

char foo (const char& * const &p );
char foo (const char& * &const p );


See http://www.parashift.com/c++-faq-lit...rrectness.html

Jul 23 '05 #2
More:

char foo (char * const &p );
char foo (char * &const p );
char foo (char &* const p );
char foo (&char * const p );

Jul 23 '05 #3
TechCrazy wrote:
What do each of these mean? Thanks. I am incredibly confused.

char foo (const char * &p );
The function takes a reference to a pointer to a constant character.
char foo (const char &* p );
Invalid.
char foo (const &char * p );
Invalid.
char foo (const char * const &p );
The function takes a reference to a constant pointer to a constant char.
char foo (const char * &const p );
Invalid.
char foo (const char &* const p );
Invalid.
char foo (const &char * const p );
Invalid.
char foo (const& char * const &p );
Invalid.
char foo (const& char * &const p );
Invalid.
char foo (const& char &* const p );
Invalid.
char foo (const& char * const p );
Invalid.
char foo (const char& * const &p );
Invalid.
char foo (const char& * &const p );


Invalid.

Jul 23 '05 #4
Rule of thumb....

draw a line thru the "*", if the word "const" appears on LHS then
what's pointed to is const. If the word const appears on RHS, then
it's a constant pointer. If it appears on both sides, then both are
constants.

From Scott Meyers effective C++ book

G
What do each of these mean? Thanks. I am incredibly confused.

char foo (const char * &p );
char foo (const char &* p );
char foo (const &char * p );

char foo (const char * const &p );
char foo (const char * &const p );
char foo (const char &* const p );
char foo (const &char * const p );

char foo (const& char * const &p );
char foo (const& char * &const p );
char foo (const& char &* const p );
char foo (const& char * const p );

char foo (const char& * const &p );
char foo (const char& * &const p );

Jul 23 '05 #5
TechCrazy wrote:
More:

char foo (char * const &p );
The function takes a reference to a constant pointer to a char.
char foo (char * &const p );
Invalid.
char foo (char &* const p );
Invalid.
char foo (&char * const p );


Invalid.

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3625
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't support. (first i compiled them with g++3.x. ERR means compiler will bark, otherwise it does accept it. Then the Comeau C/C++ 4.3.3 comes)
7
3789
by: johny smith | last post by:
Can someone please explain to me the difference between these two: function1( const int a) function2( int const a) Both seemed to compile, but what is the difference between the two above. And why would one choose one over the other. moreover, I thought there was a difference between the two below where one would not let the value change whereas the other one would not let the
7
1706
by: Martin | last post by:
I've searched this newsgroup's archives but couldn't find any posts that provided any "rule of thumb" recommendations for use of const in function parameters. I appreciate there is no need for scalar variables to have const defined, but how far should it go with pointers? The Standard Library has functions defined that specify const, for example, puts(const char *s) but why not go the extra bit and make it puts(const char * const s)?
8
2657
by: Laurijssen | last post by:
What are the advantages of using const as often as possible in C? Does it help to declare integer function arguments as const? How about pointers and automatic const integers? const int func(const int x, const float *f) { const int retval = x; return retval; }
5
2006
by: arun | last post by:
Hello Team, I have a question on const vs non const and object return vs non object return function and which one will be called ie. void foo(); vs void foo() const;
7
1527
by: James | last post by:
Hello, First off, I know this code will not compile and am not asking for someone to solve it for me. What I am asking is from the code below, how does one first define an array as a constant, and second pass the values in and out of functions? Here is the code; Thanks in advance:
7
2221
by: lovecreatesbea... | last post by:
Shoud we declare non-pointer function parameters with const keywords? int main(void){ int f(const int i); int i; f(i); return 0; }
10
2177
by: subramanian100in | last post by:
The following is a beginner's question. Suppose TYPE1 and TYPE2 are two types for which suitable ctors and operator= are defined. Suppose I have class Test { TYPE1 mem1;
2
1889
by: Jim Langston | last post by:
In my function/method paramater list I try to keep constant correctness. I.E. I would use: int Foo( const char* a, int b ) instead of int Foo( char* a, int b ) My question reguards int b. Would it be more correct to make it int Foo( const char* a, const int b ) instead? I do know the effect of this would be that I can't change b in the function, which I normally never do anyway.
0
8246
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8490
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1489
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.