LinuxQuestions.org
Visit Jeremy's Blog.
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
 
LinkBack Search this Thread
Old 05-18-2009, 02:43 AM   #1
CoderMan
Member
 
Registered: Jan 2009
Location: Gemini Capsule 25164
Distribution: Gentoo
Posts: 375
Blog Entries: 24

Rep: Reputation: 42
Question C Syntax - Passing in unknown number of arguments?


Noob question of the week for you C gurus: I need to write a wrapper
function around the mvprintw function, like so:

int smvprintw( ? )
{
// Do various checks/modifications on the first two arguments (int y,
int x) first,
// and then
return mvprintw ( ? );
}

How should I write the args for smvprintw so that I can pass all the
data correctly to mvprintw, and also do my checks on the first two args (for example, to modify them)? I'm confused by the prototype of mvprintw:

This is mvprintw as listed in the man pages:
int mvprintw(int y, int x, const char *fmt, ...);

And this is how I saw it in ncurses.h:
extern NCURSES_EXPORT(int) mvprintw (int,int, const char *,...)

I believe the "..." refers to the unknown number of items after const char * fmt. Will it suffice to do something like "int smvprintw(int y, int x, const char * fmt, void * etc)" and then "mvprintw(y, x, fmt, etc)" inside the function?
 
Old 05-18-2009, 03:42 AM   #2
khodeir
Member
 
Registered: Feb 2009
Distribution: Debian
Posts: 243

Rep: Reputation: 33
look man if you want to change the variables and have the effect in the calling function then send pointers to them
like that
to call the function :
Quote:
myfun(&x,&y);
in your function :
Quote:
void myfun(int *ptrx,int *ptry)
{
*ptrx=10 ; // to change the value of x to 10

}
any other questions??

Last edited by khodeir; 05-18-2009 at 03:43 AM.
 
Old 05-18-2009, 04:41 AM   #3
Guttorm
Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 959

Rep: Reputation: 157Reputation: 157
Look at "man va_arg" for information on how to use ... as function arguments.

But in order to pass a variable number of arguments in a function that takes a variable number of arguments, you need to find a corresponding function that takes a va_list parameter. Those functions are usually prefixed with a v, so for e.g. printf there's a vprintf. But there is a limitation on this. Functions with a variable number of arguments can't know how many arguments are called, so for example printf does this by checking the format string. (What I'm saying is that safe modification of the parameters will be tricky.)
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Spawning a process - passing arguments Kenhokie Programming 1 04-03-2009 01:51 PM
tricky syntax for passing arguments in csh aliases frerejacques Programming 1 03-23-2009 03:20 PM
bash, passing arguments Four Linux - Newbie 3 02-06-2006 08:24 AM
Passing Arguments into the Thread Function George_gk Programming 2 01-31-2005 05:03 AM
Handline passing arguments in C AMMullan Programming 9 03-22-2004 01:37 AM


All times are GMT -5. The time now is 03:11 PM.

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