how -pedantic works in gcc 
Author Message
 how -pedantic works in gcc

I'm trying to understand how -pedantic switch works with gcc. The gcc
help and also the other people comments, about this switch, have
suggested me that adding the switch I would have more warnings, but
instead one of the errors become a warning.
The following source code would show how an error would become a
warning if "pedantic" switch were to be added:

#include <string>
#include <iostream>

int main()
{
    std::string thestring = "the string";  
    std::cout << thestring.c_str() << std::endl;
    char* nonconst = thestring.c_str();
    nonconst[2] = 'y';
    std::cout << nonconst << std::endl;
    return 0;

Quote:
}

I have the source saved as pedantic.cpp, and I try to compile with:
$ g++ pedantic.cpp -o pedantic
pedantic.cpp: In function `int main()':
pedantic.cpp:8: initialization to `char *' from `const char *'
discards qualifiers

This is what I would expect, but when I add -pedantic this source
would compile, the error is changed into a warning:

$ g++ -pedantic pedantic.cpp -o pedantic
pedantic.cpp: In function `int main()':
pedantic.cpp:8: warning: initialization to `char *' from `const char
*' discards qualifiers

It is the intended functionality for the pedantic switch, and if yes,
why?

Thank you,
Val
--



Sun, 07 Aug 2005 14:10:42 GMT  
 how -pedantic works in gcc

Quote:

> I'm trying to understand how -pedantic switch works with gcc. The gcc
> help and also the other people comments, about this switch, have
> suggested me that adding the switch I would have more warnings, but
> instead one of the errors become a warning.
> The following source code would show how an error would become a
> warning if "pedantic" switch were to be added:

> #include <string>
> #include <iostream>

> int main()
> {
>     std::string thestring = "the string";
>     std::cout << thestring.c_str() << std::endl;
>     char* nonconst = thestring.c_str();
>     nonconst[2] = 'y';
>     std::cout << nonconst << std::endl;
>     return 0;
> }

> I have the source saved as pedantic.cpp, and I try to compile with:
> $ g++ pedantic.cpp -o pedantic

This is not a C program, and you are not compiling with a C
compiler.  c.l.c++ is down the hall.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!
--



Tue, 09 Aug 2005 01:38:09 GMT  
 how -pedantic works in gcc
On 19 Feb 2003 06:10:42 GMT

Quote:

> I'm trying to understand how -pedantic switch works with gcc. The gcc
> help and also the other people comments, about this switch, have
> suggested me that adding the switch I would have more warnings, but
> instead one of the errors become a warning.
> The following source code would show how an error would become a
> warning if "pedantic" switch were to be added:

> #include <string>
> #include <iostream>

<snip C++ code>

This news group is for discussing C, not C++ or the specifics of any
given compiler. A C++ news group should be able to tell you how bad your
C++ code is and a g++ (or possibly gcc) group (or mailing list) will
discuss the specifics of the compiler.
--
Mark Gordon
Paid to be a Geek & a Senior Software Developer
Currently looking for a new job commutable from Slough, Berks, U.K.
Although my email address says spamtrap, it is real and I read it.
--



Tue, 09 Aug 2005 01:38:38 GMT  
 how -pedantic works in gcc
Quote:

> I'm trying to understand how -pedantic switch works with gcc.
[...]
> #include <string>
> #include <iostream>

> int main()
> {
>     std::string thestring = "the string";  
>     std::cout << thestring.c_str() << std::endl;
>     char* nonconst = thestring.c_str();
>     nonconst[2] = 'y';
>     std::cout << nonconst << std::endl;
>     return 0;
> }

[...]

This is not a C program.  If you want to discuss C++, try
comp.lang.c++ or comp.lang.c++.moderated.  If you want to discuss how
gcc works, try gnu.gcc.help.

(I don't know why the moderator approved this.)

[After I filter out the 40+ spams a day directed at the group, I'm often
 a little careless by the time I get to the actual posts.  Sorry! -mod]

--

San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
--



Tue, 09 Aug 2005 01:39:17 GMT  
 how -pedantic works in gcc

comp.lang.c.moderated:

Quote:
> I'm trying to understand how -pedantic switch works with gcc. The gcc
> help and also the other people comments, about this switch, have
> suggested me that adding the switch I would have more warnings, but
> instead one of the errors become a warning.
> The following source code would show how an error would become a
> warning if "pedantic" switch were to be added:

> #include <string>
> #include <iostream>

> int main()
> {
>     std::string thestring = "the string";  
>     std::cout << thestring.c_str() << std::endl;
>     char* nonconst = thestring.c_str();
>     nonconst[2] = 'y';
>     std::cout << nonconst << std::endl;
>     return 0;
> }

> I have the source saved as pedantic.cpp, and I try to compile with:
> $ g++ pedantic.cpp -o pedantic
> pedantic.cpp: In function `int main()':
> pedantic.cpp:8: initialization to `char *' from `const char *'
> discards qualifiers

> This is what I would expect, but when I add -pedantic this source
> would compile, the error is changed into a warning:

> $ g++ -pedantic pedantic.cpp -o pedantic
> pedantic.cpp: In function `int main()':
> pedantic.cpp:8: warning: initialization to `char *' from `const char
> *' discards qualifiers

> It is the intended functionality for the pedantic switch, and if yes,
> why?

> Thank you,
> Val

I have no idea how this question slipped by the moderator, since it is
both compiler specific and about C++, not about C.  I would suggest

As for your program, it is meaningless in C but (even though off-topic
here) it invokes undefined behavior in C++, so all bets are off.

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



Tue, 09 Aug 2005 01:39:25 GMT  
 how -pedantic works in gcc

comp.lang.c.moderated:

        [snip]

Quote:
> This is not a C program.  If you want to discuss C++, try
> comp.lang.c++ or comp.lang.c++.moderated.  If you want to discuss how
> gcc works, try gnu.gcc.help.

> (I don't know why the moderator approved this.)

> [After I filter out the 40+ spams a day directed at the group, I'm often
>  a little careless by the time I get to the actual posts.  Sorry! -mod]

For your punishment, ten trips up and down the stairs carrying a dozen
copies of "C Unleashed".

[Sheesh!  Tough room. -mod]

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



Tue, 09 Aug 2005 14:41:40 GMT  
 how -pedantic works in gcc

Quote:


>         [snip]

> > This is not a C program.  If you want to discuss C++, try
> > comp.lang.c++ or comp.lang.c++.moderated.  If you want to discuss how
> > gcc works, try gnu.gcc.help.

> > (I don't know why the moderator approved this.)

> > [After I filter out the 40+ spams a day directed at the group, I'm often
> >  a little careless by the time I get to the actual posts.  Sorry! -mod]

> For your punishment, ten trips up and down the stairs carrying a dozen
> copies of "C Unleashed".

> [Sheesh!  Tough room. -mod]

My my, what big muscles you have -- Sweet Young Thing.

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!
--



Thu, 11 Aug 2005 13:06:07 GMT  
 how -pedantic works in gcc

Quote:


> comp.lang.c.moderated:

>    [snip]

> > This is not a C program.  If you want to discuss C++, try
> > comp.lang.c++ or comp.lang.c++.moderated.  If you want to discuss how
> > gcc works, try gnu.gcc.help.

> > (I don't know why the moderator approved this.)

> > [After I filter out the 40+ spams a day directed at the group, I'm often
> >  a little careless by the time I get to the actual posts.  Sorry! -mod]

> For your punishment, ten trips up and down the stairs carrying a dozen
> copies of "C Unleashed".

> [Sheesh!  Tough room. -mod]

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

I would have rather expected an answer like this:
"You've posted into the wrong group and we, the members of this group,
don't want/know how to answer to your question."

But on the other hand it is easier to be a jerk than help someone.

[but on the third hand, telling you where to go *is* helping you. -mod]

Thanks for nothing,
Val
--



Mon, 15 Aug 2005 09:20:44 GMT  
 how -pedantic works in gcc
Quote:




> > comp.lang.c.moderated:
> >       [snip]
> > > This is not a C program.  If you want to discuss C++, try
> > > comp.lang.c++ or comp.lang.c++.moderated.  If you want to discuss how
> > > gcc works, try gnu.gcc.help.

> > > (I don't know why the moderator approved this.)

> > > [After I filter out the 40+ spams a day directed at the group, I'm often
> > >  a little careless by the time I get to the actual posts.  Sorry! -mod]

> > For your punishment, ten trips up and down the stairs carrying a dozen
> > copies of "C Unleashed".

> > [Sheesh!  Tough room. -mod]

[...]

Val, in case you didn't realize it, Jack Klein's comment about "ten
trips up and down the stairs" was (a) directed at the moderator, not
at you, and (b) a joke.  My own (mild) annoyance was also directed
more at the moderator than at you.  (To the moderator: I'm over it,
all is forgiven.)

Quote:
> But on the other hand it is easier to be a jerk than help someone.

You posted an off-topic question to a moderated newsgroup, and it
leaked through.  I explained why it's off-topic and told you exactly
where to go to find the people who can actually answer it.  I'm quite
capable of being a jerk; trust me, this isn't what it looks like.

(Of course, I will now flame the moderator for approving this post
even though it has nothing to do with C.)

[by convention, meta-discussions are nearly always topical, in case anyone
 is wondering why this is here. -mod]

--

San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
--



Wed, 17 Aug 2005 04:31:02 GMT  
 how -pedantic works in gcc

Quote:
>I would have rather expected an answer like this:
>"You've posted into the wrong group and we, the members of this group,
>don't want/know how to answer to your question."

>But on the other hand it is easier to be a jerk than help someone.

?
That is precisely the answer you *did* get, four times. In addition,
all four replies gave suggestions as to where you *should* have
posted. I didn't see anyone being a jerk. Until now.

--
Al Balmer
Balmer Consulting

--



Wed, 17 Aug 2005 04:31:42 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Using GCC with -pedantic and -Wall

2. How portable is gcc -ansi -pedantic ??

3. Wanted: List of gcc -ansi -pedantic passing C PD programs

4. pedantic question

5. Pedantic cast question

6. gethostname() with -pedantic -ansi flags

7. Best pedantic C book?

8. C declaration (structure alignment tricks) fails under VC++ but work under gcc

9. newbie: cc works but gcc crashes on malloc

10. working in gcc!!

11. fmod() doesn't work in gcc, why ?

12. fmod() doesn't work in gcc, why ?

 

 
Powered by phpBB® Forum Software