Re: Memory allocation for an initialized character pointer;



s0suk3@xxxxxxxxx said:
On Oct 1, 5:14 am, Richard Heathfield <rjh@xxxxxxxxxxxxxxx> wrote:
s0suk3@xxxxxxxxx said:
On Oct 1, 1:05 am, Richard Heathfield <rjh@xxxxxxxxxxxxxxx> wrote:
<snip>

Therefore, even if a particular implementation defines a meaning for
void main(void), the behaviour of such a program on some *other*
(arbitrary) implementation is undefined.

So far, the bottom line remains the same: it *is* correct; it simply
isn't guaranteed to work on every compiler.

It seems that we have a terminology disagreement again. I don't see it
as being "correct". I know it fails on at least two implementations that
I use regularly.

But, speaking strictly in regard to the standard, we can say it is
correct, since it is explicitly mentioned there.

C&V, please. Where does the Standard explicitly say that void main(void) is
"correct"? Indeed, where does the Standard explicitly mention void
main(void) at all?

<snip>

In fact, does that mean that variables of
type int, long, or any type other than char, can't be used in a
strictly conforming program because their sizes are also
implementation-defined?

No, it means that the output of the program must not rely on their being
able to store values outside the minimum guaranteed range.

OK, a strictly conforming program can't rely on the order of bit-
fields or on integer ranges other than those guaranteed. But, does
that mean that such a program would be incorrect?

No. A program doesn't have to be strictly conforming to be correct. The
Standard doesn't define "correct", of course, so we have to assume that
the ordinary meaning applies, and your code:

For example:

#include <stdio.h>
#include <limits.h>

int main(void)
{
int i = 0;

#if INT_MAX >= 33000
i += 33000; // thirty-three thousand
#endif

printf("%d\n" i);
}

looks fine to me provided one is using C99 rules. In C89, it's incorrect.

According to the horrifying truth I've just learned, this program
isn't conforming

Yes, it is. It isn't *strictly* conforming, but it is conforming.

(the standard only guarantees that 'int' can
represent up to 32767), but it will never fail. Is this program
"incorrect" according to the standard?

It depends which Standard we're talking about. It's incorrect under C89,
but correct under C99.

<snip>

Alternative forms of main (other than those mandated by the Standard)
*do* constitute an extension, and one that no implementor is obliged to
provide.

But void main(void) *is* mandated by the standard,

No, it isn't.

at the line where
it mentions "or in some other implementation-defined manner".

That isn't a mandate. It's permission. Implementations are not obliged to
support void main(void). They are permitted to reject programs containing
it, or to invoke any of the usual array of ghastly or even demonic
reactions that this group so enthusiastically endorses.

Thus,
accepting void main(void) does not constitute an extension.

Yes, it does. No implementation is required to support it, so it isn't part
of the language. The Standard doesn't mention it by name, only by class -
i.e. the class of non-intmain(void) non-intmain(int,char**) entry points
that C99 calls "or in some other implementation-defined manner", which
applies equally well to all non-standard entry points. Try telling your
compiler that main returns double, or long *, or struct tm, and see how
far you get at runtime. (I once brought Windows NT to a crashing halt with
pretty flashing colours, simply by returning double from main.)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.



Relevant Pages

  • Re: Inconsistent Program Results
    ... including one of them might trivially slow down compilation, ... I wrote the above (starting with "The standard headers"). ... return void, but there's no advantage in using that. ... You're cheating yourself by ignoring warning messages. ...
    (comp.lang.c)
  • Re: help w/ c/c++ problem
    ... | Then I'm afraid that both your book and your teacher are wrong. ... I'll admit to it when the persons who spent several hundred posts ... standard explicitly allows ... 'void main', then a program that uses 'void main' is valid ...
    (comp.lang.c)
  • Re: Bid After 1S Response
    ... Assume standard Amer. ... void in diamonds and strong club suit leads me believe that ... especially since nobody else has bid diamonds. ... the minimum for responding to a 1-level suit opening bid was 6 ...
    (rec.games.bridge)
  • Re: Another note about Peter Seebachs network behavior
    ... test each code snippet step by step. ... your claim that void mainisn't standard. ...
    (comp.lang.c)
  • Re: Best book on learning C++?
    ... >> because they were told to by their (incompetent) teacher. ... >the mix of things I have always used void main. ... >Me as the customer wouldn't care how the software was programmed as long as ... Actually lots intendes to follow the standard. ...
    (alt.comp.lang.learn.c-cpp)