Topic: DEFAULT TYPE FOR VARIABLES???


Author: David R Tribble <david.tribble@noSPAM.central.beasys.com>
Date: 1998/06/09
Raw View
KNAPEN, GREGORY wrote:
>> In C++, when the type of a function is not specified, the compiler
>> assumes it is an int.

Pete Becker wrote:
> It used to, but it doesn't any more. <g> That is, C++ used to be like
> C, with a default type of int in many situations. That was abolished a
> year or so ago, and compilers are starting to enforce it.

> C9X will probably also abolish it for C.

Indeed it will.  And C9X no longer allows calling functions that are
not explicitly declared, i.e., it no longer allows implicit int
functions.

-- David R. Tribble, david.tribble@noSPAM.central.beasys.com --
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1998/06/11
Raw View
"KNAPEN, GREGORY" <gregory.knapen@bell.ca> writes:

|>  In C++, when the type of a function is not specified, the compiler
|>  assumes it is an int.

No longer, and I believe that this (mis)feature is being removed from C
in the next revision too.

|>  What is the status on variables?

Here, implicit int still reigns (I think).  However, a non-empty
declaration specifier is required.  This is also true of ISO C, although
it wasn't the case in K&R1 C.

|>  I get this strage behaviour on my compiler (g++).
|>
|>  if I declare:
|>
|>  x; // in the global namespace
|>
|>  my compiler accepts it and treats it as a variable declaration
|>  of type int.

This is the traditional treatment in C (K&R1).  ISO C (and C++) require
a non-empty declaration specifier, e.g.:

    static x ;
or
    const x ;

|>  but if I write:
|>
|>  int main()
|>  {
|>    x;  // inside the scope of main
|>  // the compiler generates an error saying x is
|>  // undeclared, I gess it is expecting an lvalue

Even in K&R1 C, this would be an expression statement, not a
declaration.

|>  }
|>
|>  Is this normal or a bug in my compiler.  If this is not a bug can
|>  someone explain what the rule is for variables.

It's not standard conform, but I don't know if I would call it a bug.
It is an attempt (probably intentional) to support legacy code.  You
might check your compiler documentation to see if there is an option to
turn this support off.

--
James Kanze    +33 (0)1 39 23 84 71    mailto: kanze@gabi-soft.fr
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique orient   e objet --
              -- Beratung in objektorientierter Datenverarbeitung


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Pete Becker <petebecker@acm.org>
Date: 1998/06/05
Raw View
KNAPEN, GREGORY wrote:
>
> In C++, when the type of a function is not specified, the compiler
> assumes it is an int.

It used to, but it doesn't any more. <g> That is, C++ used to be like C,
with a default type of int in many situations. That was abolished a year
or so ago, and compilers are starting to enforce it. C9X will probably
also abolish it for C.
 -- Pete


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "KNAPEN, GREGORY" <gregory.knapen@bell.ca>
Date: 1998/06/04
Raw View
In C++, when the type of a function is not specified, the compiler
assumes it is an int.

What is the status on variables?

I get this strage behaviour on my compiler (g++).

if I declare:

x; // in the global namespace

my compiler accepts it and treats it as a variable declaration
of type int.

but if I write:

int main()
{
  x;  // inside the scope of main
// the compiler generates an error saying x is
// undeclared, I gess it is expecting an lvalue
}

Is this normal or a bug in my compiler.  If this is not a bug can
someone explain what the rule is for variables.

Greg K.



[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/06/05
Raw View
KNAPEN, GREGORY wrote:

> In C++, when the type of a function is not specified, the compiler
> assumes it is an int.

No

> What is the status on variables?

Moot point

--

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/


[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "KNAPEN, GREGORY" <gregory.knapen@bell.ca>
Date: 1998/06/05
Raw View
In C++, when the type of a function is not specified, the compiler
assumes it is an int.

What is the status on variables?

I get this strage behaviour on my compiler (g++).

if I declare:

x; // in the global namespace

my compiler accepts it and treats it as a variable declaration
of type int.

but if I write:

int main()
{
  x;  // inside the scope of main
// the compiler generates an error saying x is
// undeclared, I gess it is expecting an lvalue
}

Is this normal or a bug in my compiler.  If this is not a bug can
someone explain what the rule is for variables.

Greg K.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]