C : Call by value or reference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nehil

    C : Call by value or reference

    Does C follow call by value convention or call by reference?
    i see that there is nothing like reference in C standard but it is
    referenced.

    still, what should be the answer for the above question?

  • Kenny McCormack

    #2
    Re: C : Call by value or reference

    In article <1184504183.456 641.240530@g4g2 000hsf.googlegr oups.com>,
    Nehil <nehilparashar@ gmail.comwrote:
    >Does C follow call by value convention or call by reference?
    i see that there is nothing like reference in C standard but it is
    >referenced.
    >
    >still, what should be the answer for the above question?
    >
    Are you the same "Nehil" who is undertaking to write
    a garbage collector for C (*)? If so, have you ever heard the
    advice "Walk before you run?"

    (*) And, no doubt, next week, the Mars lander program.

    Comment

    • Nehil

      #3
      Re: C : Call by value or reference

      On Jul 15, 6:00 pm, gaze...@xmissio n.xmission.com (Kenny McCormack)
      wrote:
      In article <1184504183.456 641.240...@g4g2 000hsf.googlegr oups.com>,
      >
      Nehil <nehilparas...@ gmail.comwrote:
      Does C follow call by value convention or call by reference?
      i see that there is nothing like reference in C standard but it is
      referenced.
      >
      still, what should be the answer for the above question?
      >
      Are you the same "Nehil" who is undertaking to write
      a garbage collector for C (*)? If so, have you ever heard the
      advice "Walk before you run?"
      >
      (*) And, no doubt, next week, the Mars lander program.
      have u changed your name or r u same as Eric Sosman?
      well, what if i want to learn the new concepts of much debate. and by
      now the garbage collector is almost done as a low lovel project. and
      all the things i've asked are related to this project only somehow.
      so if u know the answer plz reply appropriately.

      Comment

      • Richard Heathfield

        #4
        Re: C : Call by value or reference

        Nehil said:
        Does C follow call by value convention or call by reference?
        C is a 100% call-by-value language. Function arguments are expressions,
        not objects. These expressions are evaluated, and those values are
        passed to the function.

        --
        Richard Heathfield <http://www.cpax.org.uk >
        Email: -www. +rjh@
        Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
        "Usenet is a strange place" - dmr 29 July 1999

        Comment

        • Chris Dollin

          #5
          Re: C : Call by value or reference

          Nehil wrote:
          Does C follow call by value convention or call by reference?
          Call by value.

          If one wants the effects provided by call-by-reference, one has to
          implement them by hand.

          [Note that for /arrays/, it can /look like/ call by reference;
          but that isn't anything to do with parameter-passing, it's
          to do with the way C arrays decay into pointers.]
          i see that there is nothing like reference in C standard but it is
          referenced.
          Pardon?
          still, what should be the answer for the above question?
          I don't know what the answer /should/ be; I only know what it /is/.

          --
          Passed By Name Hedgehog
          "Our future looks secure, but it's all out of our hands"
          - Magenta, /Man and Machine/

          Comment

          • santosh

            #6
            Re: C : Call by value or reference

            Nehil wrote:
            Does C follow call by value convention or call by reference?
            i see that there is nothing like reference in C standard but it is
            referenced.
            >
            still, what should be the answer for the above question?
            C only supports call by value. However you can simulate call by
            reference using pointers.

            Comment

            • Roland Pibinger

              #7
              Re: C : Call by value or reference

              On Sun, 15 Jul 2007 13:22:52 +0000, Richard Heathfield wrote:
              >C is a 100% call-by-value language. Function arguments are expressions,
              >not objects. These expressions are evaluated, and those values are
              >passed to the function.
              This statement is not wrong but highly misleading. Esp. it doesn't
              cover the distinction between the following:

              void foo1 (stuct something sth);
              void foo2 (stuct something* ptr);


              --
              Roland Pibinger
              "The best software is simple, elegant, and full of drama" - Grady Booch

              Comment

              • Richard

                #8
                Re: C : Call by value or reference

                santosh <santosh.k83@gm ail.comwrites:
                Nehil wrote:
                >Does C follow call by value convention or call by reference?
                > i see that there is nothing like reference in C standard but it is
                >referenced.
                >>
                >still, what should be the answer for the above question?
                >
                C only supports call by value. However you can simulate call by
                reference using pointers.
                >
                and arrays...

                Behdad Esfahbod's daily notes on GNOME, Pango, Fedora, Persian Computing, Bob Dylan, and Dan Bern!

                Comment

                • Richard

                  #9
                  Re: C : Call by value or reference

                  rpbg123@yahoo.c om (Roland Pibinger) writes:
                  On Sun, 15 Jul 2007 13:22:52 +0000, Richard Heathfield wrote:
                  >>C is a 100% call-by-value language. Function arguments are expressions,
                  >>not objects. These expressions are evaluated, and those values are
                  >>passed to the function.
                  >
                  This statement is not wrong but highly misleading. Esp. it doesn't
                  cover the distinction between the following:
                  >
                  void foo1 (stuct something sth);
                  void foo2 (stuct something* ptr);
                  It's all "words". I suspect the OP was looking for pointers - which also
                  makes me wonder if he is a troll. Since how can he implement a garbage
                  collector and not either (a) know the answer or (b) know how to google
                  up the answer.

                  Comment

                  • Chris Dollin

                    #10
                    Re: C : Call by value or reference

                    Roland Pibinger wrote:
                    On Sun, 15 Jul 2007 13:22:52 +0000, Richard Heathfield wrote:
                    >>C is a 100% call-by-value language. Function arguments are expressions,
                    >>not objects. These expressions are evaluated, and those values are
                    >>passed to the function.
                    >
                    This statement is not wrong but highly misleading. Esp. it doesn't
                    cover the distinction between the following:
                    >
                    void foo1 (stuct something sth);
                    void foo2 (stuct something* ptr);
                    Two functions, distinguished by argument types only. So what?
                    Structs are passed by value, and pointers are passed by value.
                    What distinction are you referring to?

                    --
                    Multiple Valued Hedgehog
                    Nit-picking is best done among friends.

                    Comment

                    • Kenny McCormack

                      #11
                      Re: C : Call by value or reference

                      In article <6Ismi.24731$jY 5.12803@fe1.new s.blueyonder.co .uk>,
                      Chris Dollin <eh@electriched gehog.netwrote:
                      >Roland Pibinger wrote:
                      >
                      >On Sun, 15 Jul 2007 13:22:52 +0000, Richard Heathfield wrote:
                      >>>C is a 100% call-by-value language. Function arguments are expressions,
                      >>>not objects. These expressions are evaluated, and those values are
                      >>>passed to the function.
                      >>
                      >This statement is not wrong but highly misleading. Esp. it doesn't
                      >cover the distinction between the following:
                      >>
                      >void foo1 (stuct something sth);
                      >void foo2 (stuct something* ptr);
                      >
                      >Two functions, distinguished by argument types only. So what?
                      >Structs are passed by value, and pointers are passed by value.
                      >What distinction are you referring to?
                      Yes, we all get it. But apparently, Nillios doesn't.

                      The fact is that there is a class of programmers out there, programming
                      in C, who don't really understand the language. They neither know nor
                      care about the distinction between pointers being passed by value (which
                      is part of C) and variables being called by reference (which is not part
                      of C). They assume that they are equivalent concepts (which, to a first
                      approximation, they are) and that, thus C does support call by reference.

                      Comment

                      • Richard

                        #12
                        Re: C : Call by value or reference

                        Chris Dollin <eh@electriched gehog.netwrites :
                        Roland Pibinger wrote:
                        >
                        >On Sun, 15 Jul 2007 13:22:52 +0000, Richard Heathfield wrote:
                        >>>C is a 100% call-by-value language. Function arguments are expressions,
                        >>>not objects. These expressions are evaluated, and those values are
                        >>>passed to the function.
                        >>
                        >This statement is not wrong but highly misleading. Esp. it doesn't
                        >cover the distinction between the following:
                        >>
                        >void foo1 (stuct something sth);
                        >void foo2 (stuct something* ptr);
                        >
                        Two functions, distinguished by argument types only. So what?
                        Structs are passed by value, and pointers are passed by value.
                        What distinction are you referring to?
                        Because 99% of the time that C nOObs ask this question they are
                        enquiring how to pass a pointer to a large object as opposed to the
                        entire variable.

                        Comment

                        • Richard

                          #13
                          Re: C : Call by value or reference

                          gazelle@xmissio n.xmission.com (Kenny McCormack) writes:
                          In article <6Ismi.24731$jY 5.12803@fe1.new s.blueyonder.co .uk>,
                          Chris Dollin <eh@electriched gehog.netwrote:
                          >>Roland Pibinger wrote:
                          >>
                          >>On Sun, 15 Jul 2007 13:22:52 +0000, Richard Heathfield wrote:
                          >>>>C is a 100% call-by-value language. Function arguments are expressions,
                          >>>>not objects. These expressions are evaluated, and those values are
                          >>>>passed to the function.
                          >>>
                          >>This statement is not wrong but highly misleading. Esp. it doesn't
                          >>cover the distinction between the following:
                          >>>
                          >>void foo1 (stuct something sth);
                          >>void foo2 (stuct something* ptr);
                          >>
                          >>Two functions, distinguished by argument types only. So what?
                          >>Structs are passed by value, and pointers are passed by value.
                          >>What distinction are you referring to?
                          >
                          Yes, we all get it. But apparently, Nillios doesn't.
                          >
                          The fact is that there is a class of programmers out there, programming
                          in C, who don't really understand the language. They neither know nor
                          care about the distinction between pointers being passed by value (which
                          is part of C) and variables being called by reference (which is not
                          part
                          And, in my experience never, ever have any problems with this in the C
                          context.

                          of C). They assume that they are equivalent concepts (which, to a first
                          approximation, they are) and that, thus C does support call by reference.
                          >
                          --

                          Comment

                          • CryptiqueGuy

                            #14
                            Re: C : Call by value or reference

                            On Jul 15, 10:05 pm, Richard <rgr...@gmail.c omwrote:
                            rpbg...@yahoo.c om (Roland Pibinger) writes:
                            On Sun, 15 Jul 2007 13:22:52 +0000, Richard Heathfield wrote:
                            >C is a 100% call-by-value language. Function arguments are expressions,
                            >not objects. These expressions are evaluated, and those values are
                            >passed to the function.
                            >
                            This statement is not wrong but highly misleading. Esp. it doesn't
                            cover the distinction between the following:
                            >
                            void foo1 (stuct something sth);
                            void foo2 (stuct something* ptr);
                            >
                            It's all "words". I suspect the OP was looking for pointers - which also
                            makes me wonder if he is a troll. Since how can he implement a garbage
                            collector and not either (a) know the answer or (b) know how to google
                            up the answer.
                            Both your declarations follow pass by value. What is there in it?

                            Many poorly written C books call "simulation of pass by reference
                            using pointers" as pass by reference which confuses a lot of Newbies.
                            I feel that Call by reference is said to be supported by a language IF
                            it syntactically and semantically supports that facility. C doesn't
                            have any syntactical and semantical facility for Call by Reference.
                            People find it difficult to understand that simple concept and call
                            "simulation of pass by reference using pointers" as REAL pass by
                            reference!

                            Comment

                            • Barry Schwarz

                              #15
                              Re: C : Call by value or reference

                              On Sun, 15 Jul 2007 13:06:04 -0000, Nehil <nehilparashar@ gmail.com>
                              wrote:
                              >On Jul 15, 6:00 pm, gaze...@xmissio n.xmission.com (Kenny McCormack)
                              >wrote:
                              >In article <1184504183.456 641.240...@g4g2 000hsf.googlegr oups.com>,
                              >>
                              >Nehil <nehilparas...@ gmail.comwrote:
                              >Does C follow call by value convention or call by reference?
                              i see that there is nothing like reference in C standard but it is
                              >referenced.
                              >>
                              >still, what should be the answer for the above question?
                              >>
                              >Are you the same "Nehil" who is undertaking to write
                              >a garbage collector for C (*)? If so, have you ever heard the
                              >advice "Walk before you run?"
                              >>
                              >(*) And, no doubt, next week, the Mars lander program.
                              >
                              >have u changed your name or r u same as Eric Sosman?
                              >well, what if i want to learn the new concepts of much debate. and by
                              >now the garbage collector is almost done as a low lovel project. and
                              >all the things i've asked are related to this project only somehow.
                              >so if u know the answer plz reply appropriately.
                              You seem to be of the opinion that this group is supposed to provide
                              you with answers to even the most rudimentary questions while you make
                              no effort to research the answers yourself. You don't have to take my
                              word for it but I assure this opinion is held by very few participants
                              and they are not the ones who will help you because they are just as
                              lazy as you.

                              If you don't have a C reference, get one. Go to google (you should be
                              able to find it since you use their email) and browse the archives for
                              this group. Check the faq. These issues you call debatable have been
                              addressed repeatedly.

                              In several posts you have implied you are attempting rather complex
                              projects. In others you have demonstrated that you are woefully
                              unqualified for them. Complex tasks require firm foundations. Infants
                              learn to crawl before they walk, walk before they run, and in all
                              cases to pick themselves up after falling. If you don't want to be
                              considered a troll, don't jump off the high diving board before you
                              learn to swim.


                              Remove del for email

                              Comment

                              Working...