strcpy & declaration of functions

Geoff Rimmer geoff at cs.warwick.ac.uk
Mon Jun 12 08:57:26 AEST 1989


In article <4400001 at tdpvax> scott at tdpvax.UUCP writes:
> extern int  atoi(); or 
> int  atoi();

I prefer the former, except I would write it:
	extern int atoi( const char * );

To extern or not to extern - it really doesn't matter with FUNCTION
declarations.  In the case of variables, "extern int foo;" and "int foo;"
can be very different.  But let's not get into tentative definitions!

> I myself lean toward the first so that you know the function is not
> in the file.

Not necessarily.  If ultra.c contains the function eggnog(), and
violet.c calls eggnog(), it is usual to put the declaration of eggnog
in a header file ultra.h, and then have ultra.c and violet.c #include
ultra.h.  So, even though ultra.c is seeing the "extern int eggnog();", 
the function eggnog() *is* in the same file.

> The second question deals with strcpy().  Is it like memcpy in that if the 
> arguments memory overlap the behavior is undefined or is it different.  Is 
> pre-ANSI and ANSI different on this.

For ANSI C:

	"There are two groups of string functions defined in the
	 header <string.h>.  The first have names beginning with
	 'str'; the second have names beginning with 'mem'.  Except
	 for 'memmove', the behavior is undefined if copying takes
	 place within overlapping opjects."
		- K&R2 B3 p249.
Geoff

	/---------------------------------------------------------------\
	|	GEOFF RIMMER						|
	|	email	: geoff at uk.ac.warwick.cs			|
	|	address : Computer Science Dept, Warwick University, 	|
	|		  Coventry, England.				|
	|	PHONE	: +44 203 692320				|
	|	FAX	: +44 865 726753				|
	\---------------------------------------------------------------/

"No representation without taxation!"
	- Rik Mayall, The New Statesman.



More information about the Comp.lang.c mailing list