RE: c question



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi

> void function(char *string="default");
> 
> and be able to call it with
> 
> function();

Why not just do:

void function( char *string )
{
	if( string == NULL ) {
		string = strdup( "default" );
	}

	/* ... */

	free( string );

}

int main()
{
	function( "moo" );
	function( NULL );
}

it does mean that you can't just call "function();" - you have to put
a NULL as the argument, but it works just fine.


- ---
 _____ _         _       _____
| __  | |___ ___| |_ ___|   __|_ _ ___        Chris "Ng" Jones
| __ -| | .'|  _| '_|___|__   | | |   |  chris@black-sun.co.uk
|_____|_|__,|___|_,_|   |_____|___|_|_|    www.black-sun.co.uk
            S o f t w a r e

 "Linux is beating Windows" - David Cole, Microsoft Executive

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 5.5.3i for non-commercial use <http://www.pgpi.com>

iQA/AwUBN/R3G5hmBipjerS3EQIdVQCfd1InpOcQtR8caKRgsO3Gaqd/upcAn357
Xcl5zbjdau5jRi7Dtin1VPfP
=dVeK
-----END PGP SIGNATURE-----



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]