Raised This Month: $ Target: $400
 0% 

Function: String params call by reference?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mugwump
Senior Member
Join Date: May 2004
Old 09-28-2004 , 20:08   Function: String params call by reference?
Reply With Quote #1

In a function with prototype: func(blah, string[], strlen)

modifying this string[] in the function will affect the string in the calling subroutine?

-Mug
Mugwump is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 09-28-2004 , 20:11  
Reply With Quote #2

if its a global string
Freecode is offline
Mugwump
Senior Member
Join Date: May 2004
Old 09-28-2004 , 20:19  
Reply With Quote #3

Ugh, so this wont work?

Code:
func1(blah, string[], len) {    // modify string } func2(){    new string[48]    func1(blah, string, 47) }

If not how might I rewrite func1 so that it returns a string value, I tried this earlier and kept getting various string related errors...

Thanks,
Mug
Mugwump is offline
Mugwump
Senior Member
Join Date: May 2004
Old 09-29-2004 , 13:58  
Reply With Quote #4

Freecode, are you sure about your statement? Case in point:

Calls to get_user_name(id, name, len) treat name as call by reference and modify the calling variable in place, whether it is global or defined locally...

Anyone have the answer to my original question, or does thre above answer it?

Thanks,
Mug
Mugwump is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 09-29-2004 , 15:11  
Reply With Quote #5

AFAIK, arrays are passed by reference, and should be modifyiable from the function. I'm not 100% sure though.
__________________
hello, i am pm
PM is offline
Mugwump
Senior Member
Join Date: May 2004
Old 09-29-2004 , 20:37  
Reply With Quote #6

Gotcha, thanks.

-Mug
Mugwump is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode