Topic: Implicit return type vs. ANSI


Author: "mateus" <mateus.justino@gmail.com>
Date: Mon, 29 Jan 2007 13:16:56 CST
Raw View
Wasn't there an exception for main where when undefined it would be
void while after ANSI adoption, it became int?

> Of course not.  I think this "feature" was removed from a very
> primitive version of C++; at any rate, ISO is very clear
> (   7.1.5): "At least one type-specifier that is not a
> cv-qualifier is required in a declaration unless it declares a
> constructor, destructor or conversion function."
>
> (BTW: there has never, ever been an implicit void.  In K&R C,
> there was an implicit int.  But it has been removed from C as
> well; from the C standard (   6.7.2): "At least one type specifier
> shall be given in the declaration specifiers in each
> declaration, and in the specifier-qualifier list in each struct
> declaration and type name.")
>
> --
> James Kanze (GABI Software)             email:james.ka...@gmail.com
> Conseils en informatique orient   e objet/
>                    Beratung in objektorientierter Datenverarbeitung
> 9 place S   mard, 78210 St.-Cyr-l'   cole, France, +33 (0)1 30 23 00 34


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Ron Natalie <ron@spamcop.net>
Date: Mon, 29 Jan 2007 14:27:29 CST
Raw View
mateus wrote:
> Wasn't there an exception for main where when undefined it would be
> void while after ANSI adoption, it became int?
>
Nope.  C++ has always had explicit return types and I have never
EVER seen a compiler that assumed an implicit return to be anything
other than int.

The only gawd-awful sanctioned kludge there was to main was that
flowing off the end of main was required to be treated AS IF
a "return 0;" had been executed there.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "James Kanze" <james.kanze@gmail.com>
Date: Tue, 30 Jan 2007 09:40:37 CST
Raw View
mateus wrote:
> Wasn't there an exception for main where when undefined it would be
> void while after ANSI adoption, it became int?

No.

Back when functions could have implicit return types, there was
no void.  The whole point of implicit int is that almost all
functions returned int: some, of course, returned just a random
int value (because they contained no return statement), and it
was expected that the user ignore it.  (At this time, functions
were implicitly declared on first use as well.  No need for
header files---just use whatever functions you needed.)

This was recognized as a design flaw in C well before C++ was
invented, and C++ avoided it from the start.  C, itself, has
since adopted some of the C++ innovations: void, function
prototypes, etc.

--
James Kanze (GABI Software)             email:james.kanze@gmail.com
Conseils en informatique orient   e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S   mard, 78210 St.-Cyr-l'   cole, France, +33 (0)1 30 23 00 34


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: jdennett@acm.org (James Dennett)
Date: Tue, 30 Jan 2007 16:11:17 GMT
Raw View
Ron Natalie wrote:
> mateus wrote:
>> Wasn't there an exception for main where when undefined it would be
>> void while after ANSI adoption, it became int?
>>
> Nope.  C++ has always had explicit return types and I have never
> EVER seen a compiler that assumed an implicit return to be anything
> other than int.
>
> The only gawd-awful sanctioned kludge there was to main was that
> flowing off the end of main was required to be treated AS IF
> a "return 0;" had been executed there.

One common compiler didn't know the implicit "return 0;"
rule, and if it found no return in main would display a
diagnostic saying that "void main" had been assumed, even
though the code correctly declared main as returning int.

Fortunately later versions of that compiler have been
much more serious in attempting to implement standard
C++.

-- James

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Let_Me_Be" <Happy.Cerberus@gmail.com>
Date: Thu, 25 Jan 2007 09:47:28 CST
Raw View
I have into an issue, compiler doesn't support implicit return types,
which according to some sources should be included in the C++ ANSI
standard (implicit void).

To decide what is wrong I also tried to go thru the standard and find
something concerning this issue, but I didn't.

There is nothing concerning neighter the posibility to ommit return
type or the need to specify the return type always. (well at least I
didn't find anything)

So, to make it short, is it possible (according to ANSI C++) to write
something like this?

foo() { return; }


Thx for any hints...

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "James Kanze" <james.kanze@gmail.com>
Date: Thu, 25 Jan 2007 11:27:48 CST
Raw View
Let_Me_Be wrote:
> I have into an issue, compiler doesn't support implicit return types,
> which according to some sources should be included in the C++ ANSI
> standard (implicit void).

> To decide what is wrong I also tried to go thru the standard and find
> something concerning this issue, but I didn't.

> There is nothing concerning neighter the posibility to ommit return
> type or the need to specify the return type always. (well at least I
> didn't find anything)

> So, to make it short, is it possible (according to ANSI C++) to write
> something like this?

> foo() { return; }

Of course not.  I think this "feature" was removed from a very
primitive version of C++; at any rate, ISO is very clear
(   7.1.5): "At least one type-specifier that is not a
cv-qualifier is required in a declaration unless it declares a
constructor, destructor or conversion function."

(BTW: there has never, ever been an implicit void.  In K&R C,
there was an implicit int.  But it has been removed from C as
well; from the C standard (   6.7.2): "At least one type specifier
shall be given in the declaration specifiers in each
declaration, and in the specifier-qualifier list in each struct
declaration and type name.")

--
James Kanze (GABI Software)             email:james.kanze@gmail.com
Conseils en informatique orient   e objet/
                   Beratung in objektorientierter Datenverarbeitung
9 place S   mard, 78210 St.-Cyr-l'   cole, France, +33 (0)1 30 23 00 34


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: ark@acm.org ("Andrew Koenig")
Date: Thu, 25 Jan 2007 18:46:16 GMT
Raw View
"Let_Me_Be" <Happy.Cerberus@gmail.com> wrote in message
news:1169732365.027050.270020@s48g2000cws.googlegroups.com...

>I have into an issue, compiler doesn't support implicit return types,
> which according to some sources should be included in the C++ ANSI
> standard (implicit void).

I guess you should consider finding different sources.  Standard C++ doesn't
support implicit return types.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: kuyper@wizard.net
Date: Thu, 25 Jan 2007 12:46:56 CST
Raw View
Let_Me_Be wrote:
> I have into an issue, compiler doesn't support implicit return types,
> which according to some sources should be included in the C++ ANSI
> standard (implicit void).

Could you identify or quote those sources? I suspect that they may be
talking about something quite different from what you thought they were
talking about.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: ron@spamcop.net (Ron Natalie)
Date: Thu, 25 Jan 2007 21:42:15 GMT
Raw View
Let_Me_Be wrote:
> I have into an issue, compiler doesn't support implicit return types,
> which according to some sources should be included in the C++ ANSI
> standard (implicit void).

There has never been an implicit return type in C++ (it was int in
early C but even C doesn't allow it any more).

The absence of PARAMETERS is the same as the C concept of a void
parameter list, i.e.
 int foo()
is the same in C++ as
 int foo(void)

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]