English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 09 September 2005, 02:21   #1
girv
Mostly Harmless
 
girv's Avatar
 
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);
girv is offline  
Old 09 September 2005, 13:40   #2
OddbOd
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 );
before your function definitions?

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.
OddbOd is offline  
Old 09 September 2005, 14:50   #3
girv
Mostly Harmless
 
girv's Avatar
 
Join Date: Aug 2004
Location: Northern Ireland
Posts: 1,109
Quote:
Originally Posted by OddbOd
1) Variadic functions require prototypes
I didn't know that, I'll try it. Thanks

Quote:
Originally Posted by OddbOd
2) Where is the argument pointer ap defined and initialised?
Its missing from the above code, sorry.

Code:
VOID fmttest(
	STRPTR a_fmt,
	...
)
{
	va_list ap;

	va_start(ap, a_fmt);
	printf(a_fmt, ap);
	va_end(ap);
}
girv is offline  
 


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

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 +2. The time now is 18:11.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.48079 seconds with 13 queries