Re: default data type for global variables

Discussion in 'C++' started by Peter van Merkerk, Jul 23, 2003.

  1. "qazmlp" <> wrote in message
    news:...
    > This one compiles fine:
    >
    > // fileName.C
    > someName = 2 ;
    >
    > int main()
    > {
    > someName = someName + 2 ;
    > }


    It probably compiles because of the .c extension in file name. The .c
    extension causes some compilers to behave like a C compiler. In C++ you
    must always specify the type, which is a good practice anyway, even in
    C.

    > But, the following gives compilation error:
    >
    > int main()
    > {
    > someName = 2 ;
    > someName = someName + 2 ;
    > }
    >
    > Why? I would like to have the C++ standard word also about this.
    > Also, what is the default data type assumed in the first case?


    This is is really a C question, it is not valid C++ code. C defaults to
    int when no type is specified.

    --
    Peter van Merkerk
    peter.van.merkerk(at)dse.nl
     
    Peter van Merkerk, Jul 23, 2003
    #1
    1. Advertising

  2. Peter van Merkerk

    Jack Klein Guest

    On Wed, 23 Jul 2003 11:24:07 +0200, "Peter van Merkerk"
    <> wrote in comp.lang.c++:

    > "qazmlp" <> wrote in message
    > news:...
    > > This one compiles fine:
    > >
    > > // fileName.C
    > > someName = 2 ;
    > >
    > > int main()
    > > {
    > > someName = someName + 2 ;
    > > }

    >
    > It probably compiles because of the .c extension in file name. The .c
    > extension causes some compilers to behave like a C compiler. In C++ you
    > must always specify the type, which is a good practice anyway, even in
    > C.
    >
    > > But, the following gives compilation error:
    > >
    > > int main()
    > > {
    > > someName = 2 ;
    > > someName = someName + 2 ;
    > > }
    > >
    > > Why? I would like to have the C++ standard word also about this.
    > > Also, what is the default data type assumed in the first case?

    >
    > This is is really a C question, it is not valid C++ code. C defaults to
    > int when no type is specified.


    ....not since the 1999 update to the ISO C standard. Implicit int is
    just as dead in C as it is in C++.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
     
    Jack Klein, Jul 24, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wayne
    Replies:
    2
    Views:
    485
    Wayne
    Nov 11, 2003
  2. Daniel Bass
    Replies:
    2
    Views:
    6,911
    Daniel Bass
    Dec 31, 2003
  3. Christoph Haas
    Replies:
    5
    Views:
    290
    Christoph Haas
    Sep 23, 2006
  4. jubelbrus
    Replies:
    5
    Views:
    632
    JohnQ
    Jul 20, 2007
  5. mark4asp
    Replies:
    1
    Views:
    227
Loading...

Share This Page