Wed Nov 30 23:40:00 GMT 2005
2005/11/30, Gregory Pietsch <firstname.lastname@example.org>:
> I didn't know GNU glibc compatability was a requirement;
Most free software is written for GNU glibc. It's a benefit if
getopt_long uses the same prototype as glibc.
> The optstring parameter should be const, as I'm not modifying that, but
> declaring the argv-parameter as char * const argv is weird.
It is weird, but getopt's argv is declared const by SUSv3.
getopt_long's argv should probably be the same, if only to be
parallel. The glibc source has this to say on the topic:
The elements of ARGV aren't really const, because we permute them.
But we pretend they're const in the prototype to be compatible
with other systems.
> According to Section 220.127.116.11.1 of the C99 standard (paragraph 2,
> sub-paragraph 5), and the same place in the C89 standard, the parameters
> to main() are modifiable. Permuting is what the glibc getopt does; at
> least I'm not losing information. Does the C99 standard trump SUSv3 over
> here? Am I grasping at straws, or is my argument sane?
The argv argument of main is modifiable, and so not const, but the
standard, non-permuting getopt does not modify its argv, and so it is
const. The permuting behaviour is a really nice extension, but it
changes the prototype of the function. My inclination is to do as
glibc and lie, saying the function's const even though it's not.
More information about the Newlib