Thread: Simplest question ever! Sorry i can't work it out...!- Local variables

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    104
    Quote Originally Posted by JezW View Post
    is there no way to just send the value of a variable from one function to another?

    thanks,

    Jez
    Of course. Instead of passing the variable's address as a parameter, pass the variable itself.

  2. #2
    Registered User
    Join Date
    Apr 2009
    Posts
    18
    Quote Originally Posted by abraham2119 View Post
    Of course. Instead of passing the variable's address as a parameter, pass the variable itself.
    and how might one go about this?

    Jez

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by JezW View Post
    and how might one go about this?

    Jez
    That was described in post #7 in this thread.

    Note, however, that if you just pass the value, there is no way [1][2] that the code INSIDE the function can modify the value outside of the function - it has no access to the value.

    [1] If the parameter is an array, it becomes a pointer, and in this way, it IS possible to modify parameters that are arrays.

    [2] Beginners: Please ignore this part. Yes, a function can do anything it like, and it can, given some relatively restricted conditions modify data that was passed in by creating it's own pointer, and move back beyond the stack-frame of the current process. But we are talking the same sort of thing as if I said "you as a driver of a car can not affect other drivers of other cars" and then someone saying "But if my car is bigger/stronger, I can push the other cars around on the road" - of course, that is POSSIBLE, but you are not doing things how they should be done, and you can't do that all the time, since some cars will probably be bigger than yours. I'm just covering the fact that some pedant will point out the flaw in my categorical statement above [as I would do]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about some variables in my code
    By XodoX in forum C Programming
    Replies: 4
    Last Post: 02-03-2009, 06:29 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. how to access local variables outside loops?
    By cdkiller in forum C++ Programming
    Replies: 3
    Last Post: 09-28-2006, 06:48 PM
  4. local and global variables???
    By geo_c in forum C Programming
    Replies: 5
    Last Post: 08-23-2004, 03:02 PM
  5. local variables
    By Unregistered in forum C Programming
    Replies: 14
    Last Post: 03-20-2002, 02:55 PM