09 September 2005, 02:21 | #1 |
Mostly Harmless
Join Date: Aug 2004
Location: Northern Ireland
Posts: 1,109
|
SAS/C varargs
One for the C gurus
How do you pass a function's variable arguments to another function ? ...also known as... Why does the below code print garbage ? Code:
VOID fmttest( STRPTR a_fmt, ... ) { va_start(ap, a_fmt); printf(a_fmt, ap); va_end(ap); } ... fmttest("%d %d %d\n",1,2,3); |
09 September 2005, 13:40 | #2 |
Registered User
Join Date: Jul 2005
Location: Australia
Age: 46
Posts: 666
|
I am no C expert (I probably know a lot less than you do) however the actual call itself looks valid. As I can't give you a complete answer without complete code here are a couple of things to check:
1) Variadic functions require prototypes, I assume you have Code:
void fmttest( char *format, va_list arg_ptr ); 2) Where is the argument pointer ap defined and initialised? By the looks of things, nowhere, it should be defined with the va_list type before being initialised by va_start(). Now I think about it a bit more your code fragment looks a lot like vprintf(), maybe a quick read through this might be useful. |
09 September 2005, 14:50 | #3 | ||
Mostly Harmless
Join Date: Aug 2004
Location: Northern Ireland
Posts: 1,109
|
Quote:
Quote:
Code:
VOID fmttest( STRPTR a_fmt, ... ) { va_list ap; va_start(ap, a_fmt); printf(a_fmt, ap); va_end(ap); } |
||
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
SAS C v6.50 | Avanaboy | request.Apps | 2 | 22 April 2012 02:48 |
Sas/c | Tiddlypeeps | Coders. General | 15 | 08 February 2010 00:32 |
Sas C 6.58 | AmiCoder | request.Apps | 3 | 06 February 2010 01:19 |
SAS/C v6.50 | zerostress | request.Apps | 3 | 08 October 2007 10:35 |
Sas C V 6.0 | Jherek Carnelia | request.Apps | 1 | 20 March 2007 10:13 |
|
|