RE: c question



Yes, but what if you want to hand a function with the same name a char* or
an int. I know in C++ you can overload a function. But can you do this
with C?

On Fri, 1 Oct 1999, Chris Jones wrote:

> -----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-----
> 
> 
> -- 
> To unsubscribe: mail gnome-devel-list-request@gnome.org with "unsubscribe"
> as the Subject.
> 



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