CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by Sam Hobbs
    In other languages, when an item is passed "by reference", it is modifiable. If it is not modifiable, it is passed "by value". The modifyability of a parameter is the inherent destinction that defines the terms.

    ...

    Again, the terms "by value" and "by reference" are intended to differentiate non-modifiable and modifiable parameters (respectively), yet in C++ many parameters that are not references are often considered to be modifiable.
    No...passing by reference does not mean that the parameter is modifiable. References can allow the parameter being changed or not. At least, if the term 'reference' is used in regard to the mechanism itself instead of a description of the general mechanism of passing arguments...

  2. #17
    Join Date
    Jun 2000
    Location
    austin
    Posts
    101
    Originally posted by Sam Hobbs
    Discussions such as this do happen in this forum. That's the way it works. Sometimes the conversations don't help the person that created the thread, but if they result in something that helps others, then it usually is worthwhile.
    i can dig that...=)

    -- C

  3. #18
    Join Date
    Nov 2003
    Location
    Vienna, Austria
    Posts
    212
    Originally posted by Sam Hobbs
    Please beleive me that not everyone agrees with that. Many people would say that in:
    Code:
    void Func(char *String)
    String is passed by reference and many people would say that String is passed by value. As a pointer, String is passed by value, but as a string, String (using non-C++ terminology) is passed by reference.
    I readily believe that.

    However, in your example the question is "what is String?". Is String the pointer to the character(s)? Or is String the character(s) themselves. In the first case, String is passed by value, in the second by reference. This is why I said that the terminology depends on what you refer to.

    Paul is right, since references are not DEFINED to be addresses, they don't really have a value and you can't refer to them.

    If you pass an argument by reference or value, there is a need for a clear definition of what we refer to. But as this very thread proves, that cannot always be read from the syntax. Maybe with a unified whitespace placement convention, but that would be the first time in history that there was such a thing.
    All the buzzt
    CornedBee

  4. #19
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by Andreas Masur
    No...passing by reference does not mean that the parameter is modifiable. References can allow the parameter being changed or not. At least, if the term 'reference' is used in regard to the mechanism itself instead of a description of the general mechanism of passing arguments...
    How many times do I need to say that I am refering to the terms "by value" and "by reference" as used in the context of other languages? How many times do I need to say that a C++ reference is different?

    For example, see Argument Passing ByVal and ByRef. It says:
    Passing an argument by value means the procedure cannot modify the contents of the variable element in the calling code underlying the argument. Passing by reference allows the procedure to modify the contents in the same way that the calling code itself can.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  5. #20
    Join Date
    May 1999
    Location
    Southern California
    Posts
    12,266
    Originally posted by CornedBee
    If you pass an argument by reference or value, there is a need for a clear definition of what we refer to.
    Yes.

    The only significant point I wanted to make is that in the context of C++ the terms are not defined clearly enough to be useful. In other languages, such as VB, they are clearly defined. In VB, "by value" is the ByVal keyword and "by reference" is the ByRef keyword.
    "Signature":
    My web site is Simple Samples.
    C# Corner Editor

  6. #21
    Join Date
    Nov 2003
    Location
    Vienna, Austria
    Posts
    212
    Exactly.
    All the buzzt
    CornedBee

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured