C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Why is warning coming?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
dragoncoder
Guest





PostPosted: Fri Apr 08, 2005 11:12 pm    Post subject: Why is warning coming? Reply with quote



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/b­its/stl_threads.h: In instantiation of
`__gthread_mutex_t std::_Swap_lock_struct<0>::_S_­swap_lock':
/usr/local/include/c++/3.2.3/b­its/stl_threads.h:122: instantiated
from here /usr/local/include/c++/3.2.3/b­its/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


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Timo Geusch
Guest





PostPosted: Sat Apr 09, 2005 10:08 am    Post subject: Re: Why is warning coming? Reply with quote



dragoncoder wrote:

Quote:
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/b­its/stl_threads.h: In instantiation of
`__gthread_mutex_t std::_Swap_lock_struct<0>::_S_­swap_lock':
/usr/local/include/c++/3.2.3/b­its/stl_threads.h:122: instantiated
from here /usr/local/include/c++/3.2.3/b­its/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.

From the warning you quoted it looks like it originates in one of the files
that are included when you #include <iostream> and it has nothing to do
with your own code.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
James Kanze
Guest





PostPosted: Sat Apr 09, 2005 10:56 pm    Post subject: Re: Why is warning coming? Reply with quote



dragoncoder wrote:

Quote:
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/b­its/stl_threads.h: In instantiation of
`__gthread_mutex_t std::_Swap_lock_struct<0>::_S_­swap_lock':
/usr/local/include/c++/3.2.3/b­its/stl_threads.h:122: instantiated
from here /usr/local/include/c++/3.2.3/b­its/stl_threads.h:115:
warning: aggregate has a partly bracketed initializer

Can someone please explain me why is the warning coming?

Because the library authors of g++ don't have same opinion as to
what qualifies as "acceptable quality" as the compiler authors
do:-). (Seriously, I seem to recall looking at this, and it is
an awkward case. There are types involved that the library
writers don't know. Still, I presume that there is some way to
get the compiler to shut up, locally.)

Quote:
I read the type of a string literal in C++ is const char[], if
yes, I don't expect any warning.

The filename and linenumber of the warning don't correspond to
your declaration, so why do you think that the error is there?
The problem is in the library.

--
James Kanze mailto: [email]james.kanze (AT) free (DOT) fr[/email]
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 pl. Pierre Sémard, 78210 St.-Cyr-l'École, France +33 (0)1 30 23 00 34

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kerzum@mail.ru
Guest





PostPosted: Sun Apr 10, 2005 8:53 am    Post subject: Re: Why is warning coming? Reply with quote

I believe this gcc-specific issue should be discussed outside
of clcm, though here's the answer
If you really like warnings, you got to disable most annoying one by
one. This warning is up to gcc developers, It's likely you'll see it
while compiling any c++ source.
I recommend adding -Wno-missing-braces in order to avoid it.

If you're really interested what this warning means, here's quote from
GCC info pages:
`-Wmissing-braces'
Warn if an aggregate or union initializer is not fully bracketed.
In the following example, the initializer for `a' is not fully
bracketed, but that for `b' is fully bracketed.

int a[2][2] = { 0, 1, 2, 3 };
int b[2][2] = { { 0, 1 }, { 2, 3 } };
[end quote]

in order for compiler to silently accept constructs like
vector<T> v;
for(int i=0;i I'd also recommend using -Wno-sign-compare


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Seungbeom Kim
Guest





PostPosted: Tue Apr 12, 2005 6:53 am    Post subject: Re: Why is warning coming? Reply with quote

James Kanze wrote:
Quote:
dragoncoder wrote:
I read the type of a string literal in C++ is const char[], if
yes, I don't expect any warning.

The filename and linenumber of the warning don't correspond to
your declaration, so why do you think that the error is there?
The problem is in the library.

But in most cases with template libraries where the problem is in the
user code, the warnings or errors come from the library header files.
If the error in the user code could be diagnosed as such without exposing
all the details of the library, it would be great; but for now, it
remains to be a wish.

--
Seungbeom Kim

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
R Samuel Klatchko
Guest





PostPosted: Sat Apr 16, 2005 12:18 am    Post subject: Re: Why is warning coming? Reply with quote

dragoncoder wrote:
Quote:
#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/b­its/stl_threads.h: In instantiation of
`__gthread_mutex_t std::_Swap_lock_struct<0>::_S_­swap_lock':
/usr/local/include/c++/3.2.3/b­its/stl_threads.h:122: instantiated
from here /usr/local/include/c++/3.2.3/b­its/stl_threads.h:115:
warning: aggregate has a partly bracketed initializer

It's due to a problem in the Solaris implementation of pthreads
(although I thought it was fixed in Solaris 9). The pthread's static
mutex initializer PTHREAD_MUTEX_INITIALIZER is not bracketed properly so
the compiler kicks out a warning.

You can safely ignore it.

samuel

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.