Bug #413


main() needs to return int

Added by pzb (Peter Bowen) over 14 years ago. Updated over 11 years ago.

Target version:
ruby -v:


According to the C standard, main always needs to be declared to return an int and can take zero or two parameters. It can officially have two declarations:
int main(void)
int main(int, char **)

The attached patch adds the int return to places where it is missing and uses the more portable two parameter declaration for main. It is against the ruby_1_8_6 branch in svn.


ruby-1.8.6.p286_maindecl.patch (2.61 KB) ruby-1.8.6.p286_maindecl.patch pzb (Peter Bowen), 08/09/2008 04:36 AM
Actions #1

Updated by shyouhei (Shyouhei Urabe) over 14 years ago

No, not really.

Fact (1)

When abbreviated, a function's return value defaults to int. So,
main(int, char*);
is a 100% conforming declaration of main function for C89.

Fact (2)

IEEE Std 1003.1 says in its rationale:
"Implementations are required to support the two-argument calling
sequence, but this does not prohibit an implementation from
supporting envp as an optional third argument."
So optional third argument of main is not a bad habit.

Actions #2

Updated by pzb (Peter Bowen) over 14 years ago

On (1), the return value defaulting to int was removed in C99 (ISO/IEC 9899:1999). If the target for ruby is C89/C90, then this is fine.

Fair enough on (2).

I'm mostly trying to clean out some out of tree patches that we have been carrying around. I will take this as a reject and drop the patch.

Actions #3

Updated by nobu (Nobuyoshi Nakada) over 14 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r18459.

Actions #4

Updated by nobu (Nobuyoshi Nakada) over 14 years ago


At Sat, 9 Aug 2008 11:03:13 +0900,
Shyouhei Urabe wrote in [ruby-core:18213]:

So optional third argument of main is not a bad habit.

That envp was used in 0.95 but it hasn't been used in 1.0
already. Seems to no longer need to be there.

Nobu Nakada



Also available in: Atom PDF