[Setup-tool-hackers] extern and prototypes ...




Hi Guys,

	Just reading some more code ( trying to get xst compiled for a
demo tommorow ), and I notice a rather 'eclectic' understanding of extern.

	So, here are some ( arbitary ( but good ) ) guidelines for extern.

	* Don't use extern for functions - it is not neccessary, and it
	makes the headers wider. Simply ensure that a function prototype
	is declared in the header eg.

		void   foo      (int a);
		double baa_long (long b);

	NB. note good taste in alignment.
	NB. time spent making code beautiful is not wasted, but allows
	processing on the mental back(after) burner IMHO.
	NB. time spent making each line of code beautiful encourages you
	to decrease line count, which is also good.


	* Don't put static function prototypes inside headers - this is
	pointless, and just wrong.


	* Don't put unneccessary function prototypes inside headers - it
	is only neccessary to put prototypes for functions that will be
	used outside.


	* Ensure that all 'local' functions ie. ones used internaly in a
	module are declared 'static' eg.

	static void foo (char *a)
	{
		fprintf (stderr, "%s", a);
	};


	* _Please_ try and order static functions where neccessary to
	minimise the number of function prototypes eg.

	BAD				Good

	static int fna (int a);		static int fna (int a)
					{
	int fnb (int a)				return a;
	{				}
		return fna (a);
	}				int fnb (int a)
					{
	static int fna (int a)			return fna (a);
	{				}
		return a;
	}

	Of course - these are identical when compiled, except that the
'Good' case, does not have a (redundant) prototype that has to be
tiresomely maintained to be in-sync with the function [ eg. if you add an
argument ]. It is also quicker for the compiler - since it can resolve the
back references instantly.

	If you want to see a prime example of this being done wrong, see
pretty much every Gtk+ widget, to see it done right, see eg. gnumeric.


	So - these are my requests. 


	the 'static' function modifier makes the function local to that
module, ie. its symbolic name is not exported, and thus cannot conflict
with any other module. ie. you can have 100 callback_fn's in your program
if they are all declared staticly in different modules.

	So ... sorry to patronise everyone :-)

		Michael.

-- 
 mmeeks@gnu.org  <><, Pseudo Engineer, itinerant idiot


_______________________________________________
setup-tool-hackers maillist  -  setup-tool-hackers@helixcode.com
http://lists.helixcode.com/mailman/listinfo/setup-tool-hackers



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