Need some explanation

R

Richard Bos

Chris Hills said:
Yes a lot are asked in the embedded NG but it should not preclude them
from being asked here.

It doesn't. It merely means that if someone wants to talk about
freestanding environments, he'd be wise to mention this explicitly.

Richard
 
L

Lawrence Kirby

However there are probably as many free standing implementations as
hosted. Besides who is the authority to say half the C world is off
topic in a C language group.

The sutiation is much the same as K&R C, it isn't off-topic but if you
want talk about it you need to state so explicitly or you will most likely
be misunderstood.

Lawrence
 
L

Lawrence Kirby

On Thu, 14 Jul 2005 23:21:14 +0100, Mark McIntyre wrote:

....
This is a very old topic of discussion. The C99 standard requires main
to return an int in a hosted environment. There's no implementation
defined-ness about it, and I believe its now widely agreed that the
final phrase of 5.1.2.2.1 (1) refers to the arguments of main.

Really? I find it very hard to read it that way, and it makes very little
sense - there's no good reason to rule out other return types if the
implementation wishes to support them.

Lawrence
 
L

Lawrence Kirby

S.Tobias wrote:

....
Fortran programs are conforming C programs. (They are acceptable to gcc,
which is a conforming implementation.) So the term "conforming program" is
not terribly useful.

A particular distribution of gcc provides a collection of many different
implementations some possibly conforming, most not. While it might be
possible to contruct a Fortran compiler that is a conforming C
implementation I doubt whether gcc provides one. Note that in particular
the source file name extension affects the behaviour of the gcc compiler
so changing an extension creates a different and distinct implementation.

Lawrence
 
L

Lawrence Kirby

Good point. I am not sure if they would actually accept it. Never tried
it.

However it is incorrect as it implies main can return which it can't.

No more than void main(). void says that it doesn't return a value, not
that it can't return.

In pre-standard times int was the return type used for functions that
didn't return a value. :)
In many situations a return from main is fatal.

In a free-standing system it would be as incorrect to use int main as it
is to use void main in a hosted environment.

Not at all. It is a well established practice in C (for better or worse)
of ignoring returned values.
Though there is less harm
in using void main in a hosted environment.

Using void main() in a hosted environment has undefined behaviour, int
main is really much the same as void main in a freestanding enviroment,
except that it might be returning a value that is ignored. Of course it
depends on the forms of startup function the freestanding implementation
supports, you need to use whatever is defined.

The int return in a hosted system is stylistic. There is often nothing
returned so having a void makes no difference. If you do need to return
something then you have to put it in.

Writing void main is simply not valid in a hosted environment, void isn't
a return type for main that C supports. So this isn't a stylistic thing is
is a correctness thing.
In a free-standing system having a return the implication is that the
program could terminate.

It is a weak implication, if you know it doesn't then it doesn't.
This is not something you want to have even as
a fleeting thought. Many free standing systems are embedded systems and
safety critical.

void main() doesn't imply that main() doesn't return.
Personally I would never write a hosted application without the int
return but I would never put a return type other than void on a free-
standing system.

That assumes that the freestanding implementation gives you the choice.

Lawrence
 
M

Mark McIntyre

On Thu, 14 Jul 2005 23:21:14 +0100, Mark McIntyre wrote:

...


Really?

Yes. Lets not start this fsckwitted debate gain.
I find it very hard to read it that way,

you need new glasses.
and it makes very little
sense - there's no good reason to rule out other return types if the
implementation wishes to support them.

Yes there is. If this were so, why not also allow other return types
eg void for printf? It'd be just as logical.
 
K

Keith Thompson

Mark McIntyre said:
Yes. Lets not start this fsckwitted debate gain.


you need new glasses.


Yes there is. If this were so, why not also allow other return types
eg void for printf? It'd be just as logical.

I agree that a literal reading of 5.1.2.2.1p1 could imply that the
return type of main must be int -- i.e.,

It shall be defined with a return type of int and
with no parameters:
[example]
or with two parameters:
[example]
or in some other implementation-defined manner.

But I'm convinced that that is not the intent; rather it's just
slightly sloppy wording. Otherwise, how do you explain the
following statement in 5.1.2.2.3p1?

If the return type is not compatible with int, the termination
status returned to the host environment is unspecified.
 
M

Mark McIntyre

I agree that a literal reading of 5.1.2.2.1p1 could imply that the
return type of main must be int
But I'm convinced that that is not the intent;

Like I said, I'm not interested in resuming the debate from two years
ago ,during which Ben, Dan and many others savaged me for putting
forward much the same argument as you're attempting now. Feel free to
google for it to see the discussion points.

And in any events, comp.std.c, the right place for this debate, is
over the road. Further replies in this thread here will be ignored.
 
T

Tim Rentsch

Mark McIntyre said:
Yes. Lets not start this fsckwitted debate gain.


you need new glasses.

Lawrence Kirby's position here seems to be the stronger one. The
sentence in question, slightly abbreviated, is:

It [main] shall be defined with a return type of int and
with no parameters (stuff) or with two parameters (stuff);
or in some other implementation-defined manner.

The presence of only *one* semicolon in the sentence clearly suggests
that the clause after the semicolon should be put directly after the
verb rather than with the parallel clauses after 'and'. Otherwise,
there would also be a semicolon after 'with no parameters (stuff)'.
There isn't.
 
K

Keith Thompson

Mark McIntyre said:
Like I said, I'm not interested in resuming the debate from two years
ago ,during which Ben, Dan and many others savaged me for putting
forward much the same argument as you're attempting now. Feel free to
google for it to see the discussion points.

As you should know, the only way not to resume an old debate is not to
mention it. Making a controversial statement and then saying you
don't want to discuss it simply will not work.
 
M

Mark McIntyre

As you should know, the only way not to resume an old debate is not to
mention it. Making a controversial statement and then saying you
don't want to discuss it simply will not work.

Grin. Though I don't think I started it, naturally... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top