This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


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

Re: Declaration of main() in gcc.c



----- Original Message -----
From: "Billinghurst, David (CRTS)" <David.Billinghurst@riotinto.com>
Sent: Tuesday, April 10, 2001 2:58 AM


> I don't understand why gcc.c declares main as
>
> extern int main PARAMS ((int, const char *const *));
>
> int
> main (argc, argv)
>      int argc;
>      const char *const *argv;
>
> Shouldn't in be ...
>
> extern int main PARAMS ((int, char **));
>
> int
> main (argc, argv)
>      int argc;
>      char *argv[];
>

     Hi David,

  Well, on some systems, modifying any of the pointers in the argv array, or
even any of the strings they point to, is a big no-no.  So declaring it this
way makes sure nobody ever makes such a modification to gcc.  It would work
on some systems, but not others, and that would break gcc's compatibility.

  Technically, since the environment is going to pass a char **, there's no
problem passing it to a function that wants a const * const *; that simply
restricts the receiving function from modifying it, even if it was
theoretically modifiable.

  Note that it wasn't me who did it this way, I haven't looked into the
history, and I don't actually know all this for a fact; I'm just
extrapolating from the general principles of software engineering in order
to 'reverse engineer' the thinking of whoever wrote it that way in the first
place!

             DaveK



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