Why Is Void Main Illegal? 
Author Message
 Why Is Void Main Illegal?

Er...
this isn't flame bait, really....
flicking through the libraries volume of the Amiga Rom Kernel Manuals
I can't help noticing that VOID main is all over the place.

If void main is illegal, WHY is it so common in RKM?
whatever some people might say, the Amiga OS is unlikely to be written
by people who know C that poorly



Fri, 21 Feb 1997 08:30:02 GMT  
 Why Is Void Main Illegal?


Quote:

>Er...
>this isn't flame bait, really....
>flicking through the libraries volume of the Amiga Rom Kernel Manuals
>I can't help noticing that VOID main is all over the place.

>If void main is illegal, WHY is it so common in RKM?
>whatever some people might say, the Amiga OS is unlikely to be written
>by people who know C that poorly

The Amiga OS was written before ANSI C.  I have the first edition
here of the RKM (1986), and it always says:
main()
This was probably before the keyword `void' was even introduced
to Amiga C compilers.
There are other non-standard features about the Amiga.  My
favourite one was that you could determine if your program
had been started up from the CLI or from a Workbench icon
by declaring:

main(argc, argv)
int argc;
char **argv;
{
        if(argc==0) {
                /* Workbench stuff */
        } else {
                /* CLI stuff */
        }
        ...

Quote:
}

--
Miguel Carrasquer         ____________________  ~~~
Amsterdam                [                  ||]~  



Fri, 21 Feb 1997 07:35:19 GMT  
 Why Is Void Main Illegal?

[ Please keep your lines shorter than 75 characters ]

Quote:
>It's not illigal. It's just "neater" to have a programm return true,
>or false, or whatever the OS defines as successful programm
>termination.

It *is* illegal, the law (ANSI/ISO C standard) says so.

Casper



Fri, 21 Feb 1997 17:03:34 GMT  
 Why Is Void Main Illegal?

Quote:



>: >If void main is illegal, WHY is it so common in RKM?
>: The Amiga OS was written before ANSI C.  I have the first edition
>: here of the RKM (1986), and it always says:
>: main()
>: This was probably before the keyword `void' was even introduced
>: to Amiga C compilers.
>: There are other non-standard features about the Amiga.

>But a simple main() isn't particularly nonstandard.  I believe
>that a function whose type is undeclared is of type int.  Could
>a C lawyer out there check up on this?

A simple main() is and always has been OK.  Before the `void'
keyword, there was no other way to declare a "void" function
but to declare it as (implied) int, and exit it with a
return; or a }.   The examples in the RKM don't explicitly
return a value from main(), so when `void' was introduced
in some compilers, they changed the declarations of all
functions that were implicitly void.  This is OK for any other
function but `main'.  All this means is that this too was
done before the ANSI standard, that it was not corrected
when the standard appeared, and that it's probably safe
*on an Amiga* to declare main() as void.  But why should you?

--
Miguel Carrasquer         ____________________  ~~~
Amsterdam                [                  ||]~  



Sat, 22 Feb 1997 00:28:52 GMT  
 Why Is Void Main Illegal?


: >If void main is illegal, WHY is it so common in RKM?
: The Amiga OS was written before ANSI C.  I have the first edition
: here of the RKM (1986), and it always says:
: main()
: This was probably before the keyword `void' was even introduced
: to Amiga C compilers.
: There are other non-standard features about the Amiga.

But a simple main() isn't particularly nonstandard.  I believe
that a function whose type is undeclared is of type int.  Could
a C lawyer out there check up on this?

-- Bill Evans



Fri, 21 Feb 1997 23:00:13 GMT  
 Why Is Void Main Illegal?
|>
|> Er...
|> this isn't flame bait, really....
|> flicking through the libraries volume of the Amiga Rom Kernel Manuals
|> I can't help noticing that VOID main is all over the place.
|>
|> If void main is illegal, WHY is it so common in RKM?
|> whatever some people might say, the Amiga OS is unlikely to be written
|> by people who know C that poorly

It's not illigal. It's just "neater" to have a programm return true, or false, or whatever the OS defines as successful programm termination. If you set main up to return type 'VOID', then any return value will be given through a call to 'exit()', as opposed to just using 'return()' to return your value. It's just one of those funny things that no standard was ever defined for. Unless your OS /absouletely/ needs a return value, most of the time it doesn't matter if you give one or not.

And I wouldn't put money on how well all the programmers that worked on Amiga OS knew C. ;)

//
// Justin McKinnerney
// IDT / IIA Director of Software Engineering
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

//



Fri, 21 Feb 1997 06:45:25 GMT  
 Why Is Void Main Illegal?

: Er...
: this isn't flame bait, really....
: flicking through the libraries volume of the Amiga Rom Kernel Manuals
: I can't help noticing that VOID main is all over the place.

: If void main is illegal, WHY is it so common in RKM?
: whatever some people might say, the Amiga OS is unlikely to be written
: by people who know C that poorly

The Amiga OS wasn't even written in C, at least not originally.  It was
originally written in BCPL, which I'm told is a sort of progenitor of C.  
Knowing how totally uncivilized C was when AmidaDOS was originally
written, I shudder to think what BCPL was like.

--
                        * N E W   I M P R O O V E D   . S I G *  
                                        w i t h  
                  * W E D N E S D A Y     S P A C I N G *   ( t m )
------------------------------------------------------------------------------
T h e   a g g r e g a t e   i n t e l l i g e n c e   o n   t h i s  
p l a n e t   i s   a   c o n s t a n t .   T h e   p o p u l a t i o  n ,
h o w e v e r ,   i s   g r o w i n g .                    
------------------------------------------------------------------------------
"O K ,   s o    h e ' s   n o t   t e r r i b l y   f e a r s o m .    
B u t   h e   c e r t a i n l y   c a u g h t   u s   b y  
s u r p r i s e !"
------------------------------------------------------------------------------



Fri, 21 Feb 1997 06:43:07 GMT  
 Why Is Void Main Illegal?


Quote:
>It's not illigal. It's just "neater" to have a programm return true, or false,
> or whatever the OS defines as successful programm termination. If you set main
> up to return type 'VOID', then any return value will be given through a call
> to 'exit()', as opposed to just using 'return()' to return your value.

If you had followed the newsgroup for any period or read the FAQ you would
not have posted this.

According to the standard the only recognised return type for main is int -
anything else results in *undefined behaviour* i.e. it ceases to make
any guarantees whatsoever about what your program will do. From a practical
viewpoint a compiler is allowed to use a different stack frame for an
int function to a void function so its entirely possible (and legal) that
when the C startup code (which may be fixed library code that expects to
call an int function) will crash before your code ever starts to run.

Quote:
> It's
> just one of those funny things that no standard was ever defined for. Unless
> your OS /absouletely/ needs a return value, most of the time it doesn't matter
> if you give one or not.

The standard is clear enough - main must return int. However the implementation
may then proceed to do whatever it likes with the return value, including
discarding it. The reason it is done this way is that code you write on,
say, the Amiga remains portable and will still compile and run on other
systems which do require a return value. To help with this the standard
also defines the intent of the return values EXIT_SUCCESS, EXIT_FAILURE and 0.

--
-----------------------------------------


-----------------------------------------



Sat, 22 Feb 1997 06:42:33 GMT  
 Why Is Void Main Illegal?
Hi!

Quote:

> flicking through the libraries volume of the Amiga Rom Kernel Manuals
> I can't help noticing that VOID main is all over the place.
> If void main is illegal, WHY is it so common in RKM?

As the title "*Amiga* ROM Kernel Manuals" implies, all examples
contained therein are highly Amiga-specific. The discussion why miximg
up the return type may endanger the integrity of the stack frame does
not apply to Amigas (at least as long as structures are not involved),
and it is a "common extension" for Amiga C compilers to special-case a
main() returning void to mean a return value of 0. (Unfortunately DICE
is exempt from this.)

However, The Correct Amiga Way to define main() is of course:

LONG main(int argc, UBYTE **argv)

F'up-To: comp.sys.amiga.programmer

-- __

\XX/  MIME & any PGP V2 supported * V:+49-2225-5870 \\ for algorithms!

Don't trust hearsay! Read the reference! [Terry Ritter]



Sat, 22 Feb 1997 22:45:24 GMT  
 Why Is Void Main Illegal?
Hi!

Quote:

> The Amiga OS wasn't even written in C, at least not originally.  It was
> originally written in BCPL, which I'm told is a sort of progenitor of C.  

Please do not spread discrediting misinformation about the AmigaOS.
[0.5 :-)]

The AmigaOS is not monolithic. Its kernel and low-level routines have
originally been written in assembly, the rest has been written in C.
The only exception to this is the DOS, which is an adaption of
Metacomco's Tripos and has thus been written in BCPL. As of OS Rele-
ase 2, C replaced BCPL nearly completely.

Quote:
> Knowing how totally uncivilized C was when AmidaDOS was originally
> written, I shudder to think what BCPL was like.

The worst thing about BCPL is that it left two {*filter*} marks on the
AmigaOS: The BPTR (BCPL pointer) which is a real pointer divided by
four, which leads to unreasonable alignment requirements, and the BSTR
which is a BPTR to an array of bytes with the length in the first
byte, as opposed to the otherwise global adoption of C strings in the
Amiga OS.

F'up-To: comp.sys.amiga.programmer

-- __

\XX/  MIME & any PGP V2 supported * V:+49-2225-5870 \\ for algorithms!

Those were the days, when sex was dirty
and the air was clean! [Conny Koenig]



Sat, 22 Feb 1997 22:53:49 GMT  
 Why Is Void Main Illegal?

Quote:

>ANSI/ISO C standard is /not/ the law. Whatever compiler you are using is.
>If the compiler you're using doesn't support any ANSI/ISO standard,
>then I promice, you won't be coding ANSI/ISO standard.

The ANSI standard isn't the law - it's just a good idea.

-jim



Sun, 23 Feb 1997 04:49:12 GMT  
 Why Is Void Main Illegal?


Quote:
>The Amiga OS wasn't even written in C, at least not originally.  It was
>originally written in BCPL, which I'm told is a sort of progenitor of C.  
>Knowing how totally uncivilized C was when AmidaDOS was originally
>written, I shudder to think what BCPL was like.

BCPL was (is) a great language. At the time C was an evolving not particularly
well established language whereas BCPL had its wrinkes ironed out many
years previously!

--
-----------------------------------------


-----------------------------------------



Sat, 22 Feb 1997 00:57:19 GMT  
 Why Is Void Main Illegal?


Quote:

>I keep reading this here, but all I see in the standard itself is
>that if main() returns without a value, the termination status
>returned to the OS is undefined.

>Undefined != illegal

Ahem.

After  posting this, I got email from someone whose who suggested
that I read the FAQ more carefully. I replied to his mail with a cc
to P. J. Plauger, who replied that the intent of the Standard is
to permit only the two declarations for main shown in the Standard
itself, ie.:

         int main(void)
         int main(int, char **)

Mr. Plauger pointed out that other declarations may work
on some systems, but won't be portable.

I'm sorry if I confused the issue with my earlier, ill-considered post.

--
"Obviously unlike you people, I don't have time to edit the newsgroups line



Sun, 23 Feb 1997 21:17:06 GMT  
 
 [ 27 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Why Is Void Main Illegal?

2. void main(void) illegal??

3. what's the difference between void main(void) and int main(void)

4. Why Is Void Main(Void) Funny?

5. Why Is Void Main(Void) Fu

6. Why Is Void Main(Void) Funny?

7. Why Is Void Main(Void)???

8. main(void) vs void main ()

9. void main(void) or int main() ??

10. Why am i getting a exception illegal operation?

11. main() vs int main() vs int main(void)

12. newbie question....int main, void main, main

 

 
Powered by phpBB® Forum Software