which language allows you to change an argument's value?

Erik Wikström Erik-wikstrom at telia.com
Sun Sep 30 13:53:24 EDT 2007


On 2007-09-30 18:49, Summercool wrote:
> On Sep 30, 4:18 am, 7stud -- <dol... at excite.com> wrote:
>> SpringFlowers AutumnMoon wrote:
>> > we have no way
>> > of knowing what we pass in could get changed.
>>
>> Sure you do.  You look at the function's signature.  In order to use
>> someone else's library, you have to know the function's signature.  And
>> the signature explicitly tells you whether the value you pass in could
>> be changed.
> 
> do you mean in C++?  I tried to find signature in two C++ books and it
> is not there.  Google has a few results but it looks something like
> prototype.  Is signature the same as the function prototype in the .h
> file?

A signature is what is required to identify a function and includes
return type, name of function and the types of the parameters, while it
looks just like a prototype it is not. A prototype is something you
write to satisfy your compiler while a signature identifies a function.
Below are some examples of signatures, only the last can modify the
values of its parameter.

  void foo(int, float)
  std::string bar(const std::string&, int, int)
  void baz(std::string&)

> If so, don't we usually just include <___.h> and forget about
> the rest.  Documentation is fine although in some situation, the
> descriptions is 2 lines, and notes and warnings are 4, 5 times that,
> and the users' discussing it, holding different opinion is again 2, 3
> times of that length.

Unless you read the documentation how do you know which files to
include? And what documentation are you reading which does not clearly
specify the functionality of the functions described?

> I think in Pascal and C, we can never have an
> argument modified unless we explicitly allow it, by passing in the
> pointer (address) of the argument.

In C++ the arguments cannot be modified unless you either pass a pointer
to a non-const object or a non-const reference, so it is just as
explicit. (Notice that it is possible to cast the constness away, but
doing is extremely dangerous and should not be done.)

> also i think for string, it is a bit different because by default,
> string is a pointer to char or the address of the first char in C and C
> ++.  So it is like passing in the address already.

No. A string in C++ is a string, a char array or a pointer to a char is
something different.

> it is when the
> argument n is something like 1 that makes me wonder.


Get a good book on whatever language you are interested in (I do not
know which it is since you are all over the place) and read up on that
languages references, if you still do not understand after that ask your
questions in the group discussing that language.

-- 
Erik Wikström



More information about the Python-list mailing list