LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-01-2003, 03:26 PM   #1
dhanakom
LQ Newbie
 
Registered: Jul 2003
Location: Birmingham
Posts: 20

Rep: Reputation: 0
parameter passing mechanisms


Hi,

can someone tell me why and when one of the following is prefered over the other

pass by reference using reference arguments

pass by reference using pointer arguments

Both are insecure (unless const is used to qualify the parameters)
but dont both of them essentially have the same dynamics ?? so why is one prefered over the other ??

Please eluciate.

Thanks
 
Old 09-01-2003, 03:45 PM   #2
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
You can't do pointer arithmetic on references. For example, if I pass a function a pointer to a single character, there's nothing to stop that function treating the argument as an array of characters. This couldn't happen if the function required a reference to a character instead of a pointer to a character.

Alex
 
Old 09-01-2003, 05:15 PM   #3
jinksys
Member
 
Registered: Aug 2003
Location: 63123
Distribution: OpenSuSE/Ubuntu
Posts: 418

Rep: Reputation: 31
I agree with the previous post.

Pros with passing References:
When passing a reference, the code inside of the function treats the reference just like a global variable - that is...no need to use * operators and changes to the reference changes the passed variable.

Cons with passing References:
References are not pointers and cannot be manipulated
via pointer arithmatic.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
setting up scp alias under bash - parameter passing problem gjr Linux - Newbie 4 06-08-2005 07:38 AM
Passing hash of hashes as a parameter (Perl) rose_bud4201 Programming 8 04-21-2005 08:18 PM
Passing one php function result as a parameter to another php function davee Programming 13 09-12-2004 01:08 PM
IPC Mechanisms ananthbv Programming 5 12-20-2003 12:57 PM
Passing parameter to kernel when booting from floppy NewtoSlack Slackware 1 10-10-2003 09:24 PM


All times are GMT -5. The time now is 11:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration