C-Like Strings?

  • Thread starter Lefteris Laskaridis
  • Start date
L

Lefteris Laskaridis

Can anybody tell me what is the use of specifiying a function argument as
char const* const& instead of char const*?

for example:

char const* const& function( char const* const& someString )

-
Thanx
 
R

Ron Natalie

Lefteris Laskaridis said:
Can anybody tell me what is the use of specifiying a function argument as
char const* const& instead of char const*?

for example:

char const* const& function( char const* const& someString )

-
There's no real point in doing the above. Pointers are usually just passed in
registers, so const references to them aren't any better than just passing a copy.

Now if it were:
char const* & someString...
It would allow the function to actually change the pointer passed.
 
K

Kevin Saff

Lefteris Laskaridis said:
Can anybody tell me what is the use of specifiying a function argument as
char const* const& instead of char const*?

for example:

char const* const& function( char const* const& someString )

-
Thanx

There is no point. The person who wrote the function probably thought that
returning a reference would be more efficient than just returning a pointer.
However, it is highly unlikely that a reference is easier to transfer than a
pointer, since the obvious implementation of passing by reference is just to
pass a pointer to the object. So whoever wrote this was probably just
confused.

Worse, returning by reference requires that function returns a reference to
an object outside of the function, which hurts maintenance flexibility. It
is hard to imagine an occasion to use this rather than just:

char const *function (char const *someString);

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top