Why is warning coming?

D

dragoncoder

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
 
N

news.individual.net

dragoncoder said:
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++.
 
M

Mark McIntyre

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.
 
C

CBFalconer

dragoncoder said:
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.
 
M

Martin Ambuhl

dragoncoder said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top