This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: groff: conflict with prototype arg name in getopt.h


> From: Roland McGrath <roland@gnu.org>
> Date: Sun, 22 Apr 2001 15:16:15 -0400 (EDT)
> 
> as the maintainers of getopt, we need to be sensitive to the
> portability needs of other GNU packages.  The same rules should
> apply now to getopt as did in the old days when it lived in
> /gd/gnu/lib.

Yes.  Another way to say it is that getopt code should conform to the
standards in two different ways:

   1.  The code should implement the getopt interface, and in POSIX
   1003.1-200x d6 this means that <unistd.h> should declare getopt.
   d6 does not specify getopt.h, but getopt.h should undoubtedly use
   the same rules that the other standard headers do, and those rules
   are what Ulrich Drepper was referring to.

   2.  The code should be portable application code, since it is used
   by many GNU applications in preference to the system getopt.  This
   means the code should follow the rules for portable application
   code, and one of these rules is that such code cannot use
   identifiers like __foo unconditionally.  These rules are what
   Werner Lemberg was referring to.

For (2), it's not vital for getopt to religiously avoid all
identifiers of the form __foo; just the identifiers that cause
problems in practice in applications.  __argc seems to be one such
identifier.

Simply renaming __argc to ___argc would do the trick, would it not?
I'd do the same for __argv, for consistency.  This solution would
address both Ulrich's concerns for documentation and Werner's concerns
for compatibility.  It's an easy fix, so we might as well do it even
though it isn't necessary for GNU platforms proper.  Here's a proposed
patch to do this.

2001-04-23  Paul Eggert  <eggert@twinsun.com>

	* posix/getopt.h (getopt_long, getopt_long_only, _getopt_internal):
	Rename __argc to ___argc in prototypes to avoid compatibility
	problems with systems that reserve the identifier "__argc".
	Similarly for __argv.

--- getopt.h	Sat Apr 21 20:30:07 2001
+++ getopt.h.fix	Mon Apr 23 12:07:34 2001
@@ -142,20 +142,21 @@ struct option
 /* Many other libraries have conflicting prototypes for getopt, with
    differences in the consts, in stdlib.h.  To avoid compilation
    errors, only prototype getopt for the GNU C library.  */
-extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
+extern int getopt (int ___argc, char *const *___argv, const char *__shortopts);
 # else /* not __GNU_LIBRARY__ */
 extern int getopt ();
 # endif /* __GNU_LIBRARY__ */
 
 # ifndef __need_getopt
-extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
+extern int getopt_long (int ___argc, char *const *___argv,
+			const char *__shortopts,
 		        const struct option *__longopts, int *__longind);
-extern int getopt_long_only (int __argc, char *const *__argv,
+extern int getopt_long_only (int ___argc, char *const *___argv,
 			     const char *__shortopts,
 		             const struct option *__longopts, int *__longind);
 
 /* Internal only.  Users should not call this directly.  */
-extern int _getopt_internal (int __argc, char *const *__argv,
+extern int _getopt_internal (int ___argc, char *const *___argv,
 			     const char *__shortopts,
 		             const struct option *__longopts, int *__longind,
 			     int __long_only);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]