Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: porting PAM

From: Tom Cosgrove <tom.cosgrove(at)arches-consulting.com>
Date: Wed May 28 2003 - 06:55:24 EDT


>>> "sven_dehmlow@gmx.de" 28-May-03 13:29 >>>
>
> On Tue, 27 May 2003 invad3rkim@flexcheck.net wrote:

(Not sure why this is on tech@ ... And donning my flame-proof suit for all the slight inaccuracies that people will no doubt roast me for...)

Err... that's fairly standard C.

Make sure you know the difference between a function declaration, a function definition, and a function invocation.

Function invocation is calling a function:

  rv = strlcpy(dest, src, sizeof(dest)) ;

Functions should be prototyped before being called. This tells the compiler what types of arguments should be expected in each position, so that the compiler can tell you if you make a mistake when calling the function. Functions can be declared either with or without names for the parameters, but they must have types. Functions are typically declared in header files (.h), except for static functions, which are usually declared at the top of the module (.c file) they are used in:

   size_t strlcpy(char *dst, const char *src, size_t size) ;

Do you need help?X

   -or-

   size_t strlcpy(char *, const char *, size_t) ;

Functions need to be defined so they exist. (!) Parameters must be given names so that they can be referred to within the function. There are two ways of doing this, the original method and the ANSI method. The original K&R way of doing this listed the names of the paramters and then re-listed the names with the types:

   size_t
   strlcpy(dst, src, size)

      char *dst ;
      const char *src ;    /* const not avail in trad. C */
      size_t size ;
   {
      /* Implementation goes here */

   }

The ANSI method of specifying the function header is much better:

   size_t strlcpy(char *dst, const char *src, size_t size)    {

      /* Implementation goes here */
   }

Note that function declarations have a ; after the closing ) following the parameters (i.e. no function body).

Do you need more help?X

My personal preference is for the first style of declaration, including names for the parameters, since this can be created by a quick YP in vi from the first line of the function definition; just add a ";" at the end.

And with that all behind us, to directly answer your question:

> > I don't really understand how function prototypes can get away with

That's the difference between a function prototype/declaration, and the definition of the function. The function body refers to paramters based on the first line of its definition. The compiler should complain if the first line of the definition does not match the declaration (if any).

Hope this helps

Tom Received on Wed May 28 07:30:34 2003

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:48:40 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library