LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 06-14-2006, 08:48 AM   #1
vikasumit
Member
 
Registered: Apr 2006
Location: Delhi, India
Distribution: Fedore , CentOs, Debian
Posts: 121

Rep: Reputation: 15
Talking c++ code syntax help, : Passing by Reference or val ??


Hi,

I got stuck with code please help me understand what is it doing ..

Code:
int authcustomcommon(const char *user, const char *pass,
        int (*callback)(struct authinfo *, void *),
                        void *arg)
{
	struct authinfo auth;
	int rc;

	memset(&auth, 0, sizeof(auth));

	rc=do_auth_custom(user, &auth);
....
}

static int do_auth_custom(const char *userid, struct authinfo *authinfo)
{
...
// I need to write code here to put values in auth struct variable pass to this function ....
...
}
In the above code, I have a structure called authinfo, variable name auth ...


this value is pass to below function, but I am not sure which value I need to set?
like in structure I have

Code:
struct authinfo{
<DATATYPE> sysusername 
}

I need to set sysusername from called function as this value is used by calling function

I know this basic question but I did C++ 7 yrs ago on windows platform...

for your reference, this is code of Courier MTA's authentication module for Custom authentication Method ...

(file is : preauthcustom.c in courier-auth library)

Thanks
 
Old 06-14-2006, 09:48 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
It looks like you are receiving a pointer to the structure so when you change the value you want to dereference the field:
Code:
authinfo->sysusername = <your data goes here>
However it may not be that simple if sysusername is a character array, since you can't do direct assignment, rather you probably want to use a function that will copy the contents across.
 
Old 06-15-2006, 12:26 AM   #3
vikasumit
Member
 
Registered: Apr 2006
Location: Delhi, India
Distribution: Fedore , CentOs, Debian
Posts: 121

Original Poster
Rep: Reputation: 15
Hi,

Can you explain me the signature of function and its call or can you point out how i search that concept ?

Thanks
 
Old 06-15-2006, 02:46 AM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
The signature consists of three parts:
  • The return type
  • The function identifier
  • The arguments, in parenthesis
so given:
Code:
int authcustomcommon(const char *user, const char *pass,
        int (*callback)(struct authinfo *, void *),
                        void *arg)
  • The return type is an int
  • The identifier is authcustomcommon
  • There are four argument as follows:
    1. user, a character array
    2. pass, a character array
    3. callback, a pointer to a function
      • return an int
      • identifier callback
      • argument list
        1. a pointer to the struct authinfo
        2. a pointer
    4. arg, a pointer
 
Old 06-15-2006, 08:54 AM   #5
vikasumit
Member
 
Registered: Apr 2006
Location: Delhi, India
Distribution: Fedore , CentOs, Debian
Posts: 121

Original Poster
Rep: Reputation: 15
Hi,

your explaination seems good

And Help me moving forward with my new problem

Will tell you if i don't get it solved myself

Thanks for info
 
  


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
small syntax problem with C code (implemented in Code Composer Studio) illiniguy3043 Programming 6 01-07-2008 02:14 AM
C++ / Passing a variable by reference to a class member function. sepulture Programming 12 11-15-2005 10:23 PM
passing variables by reference in javascript djgerbavore Programming 2 06-07-2005 11:34 PM
Problem passing string::size_type by reference (C++) timhardy Programming 2 04-24-2005 05:14 PM
passing passing variable in Java as reference djgerbavore Programming 3 11-10-2004 02:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:34 PM.

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
Open Source Consulting | Domain Registration