Why is warning coming?

Discussion in 'C Programming' started by dragoncoder, Apr 8, 2005.

  1. dragoncoder

    dragoncoder Guest

    Hello all,

    I am working on Solaris 9 with gcc 3.2.3. Please consider the following
    code.

    // a3.cxx

    #include <iostream>

    using namespace std;

    int main() {
    const char str[] = "abc";
    cout << str << endl;
    return 0;
    }

    bash-2.05$ g++ a3.cxx -ansi -Wall -pedantic
    /usr/local/include/c++/3.2.3/bits/stl_threads.h: In instantiation of
    `__gthread_mutex_t std::_Swap_lock_struct<0>::_S_swap_lock':
    /usr/local/include/c++/3.2.3/bits/stl_threads.h:122: instantiated
    from here
    /usr/local/include/c++/3.2.3/bits/stl_threads.h:115: warning: aggregate
    has a
    partly bracketed initializer

    Can someone please explain me why is the warning coming? I read the
    type of a string literal in C++ is const char[], if yes, I don't expect
    any warning.

    Please help.

    Pankaj
     
    dragoncoder, Apr 8, 2005
    #1
    1. Advertising

  2. "dragoncoder" <> wrote in message
    news:...
    > Hello all,
    >
    > I am working on Solaris 9 with gcc 3.2.3. Please consider the following
    > code.
    >
    > // a3.cxx
    >
    > #include <iostream>
    >
    > using namespace std;
    >
    > int main() {
    > const char str[] = "abc";
    > cout << str << endl;
    > return 0;
    > }
    >
    > bash-2.05$ g++ a3.cxx -ansi -Wall -pedantic
    > /usr/local/include/c++/3.2.3/bits/stl_threads.h: In instantiation of
    > `__gthread_mutex_t std::_Swap_lock_struct<0>::_S_swap_lock':
    > /usr/local/include/c++/3.2.3/bits/stl_threads.h:122: instantiated
    > from here
    > /usr/local/include/c++/3.2.3/bits/stl_threads.h:115: warning: aggregate
    > has a
    > partly bracketed initializer
    >
    > Can someone please explain me why is the warning coming? I read the
    > type of a string literal in C++ is const char[], if yes, I don't expect
    > any warning.
    >
    > Please help.
    >
    > Pankaj
    >


    Try comp.lang.c++.
     
    news.individual.net, Apr 8, 2005
    #2
    1. Advertising

  3. On 8 Apr 2005 01:40:40 -0700, in comp.lang.c , "dragoncoder"
    <> wrote:

    >Hello all,
    >
    >I am working on Solaris 9 with gcc 3.2.3. Please consider the following
    >code.
    >
    >// a3.cxx
    >
    >#include <iostream>


    this is C++. You're in the wrong group.


    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
     
    Mark McIntyre, Apr 8, 2005
    #3
  4. dragoncoder

    CBFalconer Guest

    dragoncoder wrote:
    >
    > I am working on Solaris 9 with gcc 3.2.3. Please consider the
    > following code.


    Allright. comments follow.

    >
    > // a3.cxx


    Invalid unless you have a C99 compiler. Ill advised in newsgroups,
    because of line wrapping. With gcc you need to run it with
    --std=C99. Don't forget -pedantic -W -Wall.

    >
    > #include <iostream>


    illegal include file name.

    >
    > using namespace std;


    Syntax error

    >
    > int main() {


    Better to use "int main(void)"

    > const char str[] = "abc";
    > cout << str << endl;


    cout and endl are undeclared. Shifting by the value of a pointer
    to a char seems singularly unproductive.

    > return 0;
    > }
    >
    > bash-2.05$ g++ a3.cxx -ansi -Wall -pedantic


    g++ is normally used to compile C++ programs. This group is
    comp.lang.c. This is a different language.

    > /usr/local/include/c++/3.2.3/bits/stl_threads.h: In instantiation of
    > `__gthread_mutex_t std::_Swap_lock_struct<0>::_S_swap_lock':
    > /usr/local/include/c++/3.2.3/bits/stl_threads.h:122: instantiated
    > from here
    > /usr/local/include/c++/3.2.3/bits/stl_threads.h:115: warning: aggregate
    > has a partly bracketed initializer
    >
    > Can someone please explain me why is the warning coming? I read the
    > type of a string literal in C++ is const char[], if yes, I don't
    > expect any warning.


    It may be closely related to your carelessness in posting this
    off-topic mess on c.l.c.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
     
    CBFalconer, Apr 8, 2005
    #4
  5. dragoncoder wrote:
    > Hello all,
    >
    > I am working on Solaris 9 with gcc 3.2.3. Please consider the following
    > code.


    No, because it is not C. It is in fact about a particular
    implementation (g++) and its implementation of a C++ header
    (stl_threads.h) that is not even standard C++. Please ask C++ questions
    in a C++ newsgroup and gcc or gnu questions in a gcc or gnu newsgroup.

    BTW, your code produces no errors or warnings when compiled with gcc
    without thread support or with bcc32. That's a hint.
     
    Martin Ambuhl, Apr 8, 2005
    #5
    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. Steve Holden

    PyCon is Coming! PyCon is Coming!

    Steve Holden, Jan 5, 2006, in forum: Python
    Replies:
    0
    Views:
    316
    Steve Holden
    Jan 5, 2006
  2. Replies:
    1
    Views:
    494
    alessandro basili
    Sep 21, 2006
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    909
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,996
    Smokey Grindel
    Dec 2, 2006
  5. Garg
    Replies:
    5
    Views:
    280
    Andrew Thompson
    Dec 11, 2006
Loading...

Share This Page