public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Bug in cmath namespace
@ 2006-01-30 14:23 Jens Vollinga
  2006-01-30 14:27 ` John Love-Jensen
  2006-01-30 15:39 ` Gabriel Dos Reis
  0 siblings, 2 replies; 7+ messages in thread
From: Jens Vollinga @ 2006-01-30 14:23 UTC (permalink / raw)
  To: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 803 bytes --]

Hi,

I want to define classes called sin,cos,etc. and include the cmath header at
the same time. I thought this would work since I don't say "using namespace
std;" anywhere. But it seems that by including cmath these functions appear
not only in namespace std, but also in the global namespace. The following
stripped-down program compiles with gcc 3/4, but it shouldn't (according to
the standard, since it doesn't say std::sin):

#include <cmath>

int main()
{
    double x = sin(2.0);
    return 0;
}

I am not really sure whether this is a bug with respect to the ISO standard
or whether I made a mistake here. Does anybody know why gcc/libstc++ behaves
like that?

Jens

-- 
10 GB Mailbox, 100 FreeSMS/Monat http://www.gmx.net/de/go/topmail
+++ GMX - die erste Adresse für Mail, Message, More +++

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Bug in cmath namespace
  2006-01-30 14:23 Bug in cmath namespace Jens Vollinga
@ 2006-01-30 14:27 ` John Love-Jensen
  2006-01-30 14:49   ` Jens Vollinga
  2006-01-30 15:39 ` Gabriel Dos Reis
  1 sibling, 1 reply; 7+ messages in thread
From: John Love-Jensen @ 2006-01-30 14:27 UTC (permalink / raw)
  To: Jens Vollinga, MSX to GCC

Hi Jense,

> I am not really sure whether this is a bug with respect to the ISO standard
> or whether I made a mistake here. Does anybody know why gcc/libstc++ behaves
> like that?

Not a bug.

GCC's g++ includes the C <math.h>, #undef's the macros, does a "using ::sin"
from the global namespace, and adds inline versions of sin(float) and
sin(long double).

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Bug in cmath namespace
  2006-01-30 14:27 ` John Love-Jensen
@ 2006-01-30 14:49   ` Jens Vollinga
  2006-01-30 14:57     ` John Love-Jensen
  2006-01-30 14:57     ` random
  0 siblings, 2 replies; 7+ messages in thread
From: Jens Vollinga @ 2006-01-30 14:49 UTC (permalink / raw)
  To: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 792 bytes --]

Hi,

> GCC's g++ includes the C <math.h>, #undef's the macros, does a "using
> ::sin"
> >from the global namespace, and adds inline versions of sin(float) and
> sin(long double).

thanks for the fast reply.
My problem was not to understand what gcc does. gcc works like you described
it above. My problem is whether gcc does it correctly according to the ISO
standard. In paragraph 4 of section 17.4.1.2 in that standard it says that
there should be no ::sin if you include cmath, only a std::sin. But since I
am not well trained in legal speak and have only a '98 draft version of the
standard available I am not sure if a am right or wrong.

Jens

-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Bug in cmath namespace
  2006-01-30 14:49   ` Jens Vollinga
@ 2006-01-30 14:57     ` John Love-Jensen
  2006-01-30 14:57     ` random
  1 sibling, 0 replies; 7+ messages in thread
From: John Love-Jensen @ 2006-01-30 14:57 UTC (permalink / raw)
  To: Jens Vollinga, MSX to GCC

Hi Jens,

Sorry for the typo on your name.  I'm used to typing "Love-Jensen" and my
fingers didn't stop typing in time.  :-)

I *believe* 17.4.1.2.4 for <cmath> requires the std::sin symbol, but does
not preclude global namespace ::sin.

But... I'm not assuredly sure if ::sin is to be expected, or if it is an
implementation detail.  Or if I'm mistaken entirely and ::sin should not be
present at all.

(My druthers would be that ::sin is not present at all.  C'est la vie.)

Sincerely,
--Eljay

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Bug in cmath namespace
  2006-01-30 14:49   ` Jens Vollinga
  2006-01-30 14:57     ` John Love-Jensen
@ 2006-01-30 14:57     ` random
  2006-01-30 15:10       ` Jens Vollinga
  1 sibling, 1 reply; 7+ messages in thread
From: random @ 2006-01-30 14:57 UTC (permalink / raw)
  To: Jens Vollinga; +Cc: gcc-help

Jens Vollinga wrote:
> Hi,
>
>   
>> GCC's g++ includes the C <math.h>, #undef's the macros, does a "using
>> ::sin"
>> >from the global namespace, and adds inline versions of sin(float) and
>> sin(long double).
>>     
>
> thanks for the fast reply.
> My problem was not to understand what gcc does. gcc works like you described
> it above. My problem is whether gcc does it correctly according to the ISO
> standard. In paragraph 4 of section 17.4.1.2 in that standard it says that
> there should be no ::sin if you include cmath, only a std::sin. But since I
> am not well trained in legal speak and have only a '98 draft version of the
> standard available I am not sure if a am right or wrong.
>
>   
g++ is wrong here, but it is unlikely to be fixed, and also in future
versions of the standard it is likely that it will be allowed to put sin
into the global namespace (as nearly everybody does anyway)

Chris

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Bug in cmath namespace
  2006-01-30 14:57     ` random
@ 2006-01-30 15:10       ` Jens Vollinga
  0 siblings, 0 replies; 7+ messages in thread
From: Jens Vollinga @ 2006-01-30 15:10 UTC (permalink / raw)
  To: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 440 bytes --]

Hi,

> g++ is wrong here, but it is unlikely to be fixed, and also in future
> versions of the standard it is likely that it will be allowed to put sin
> into the global namespace (as nearly everybody does anyway)

Well, then it seems I have to get used to dirty workarounds ... :-(

Thanks!
Jens

-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Bug in cmath namespace
  2006-01-30 14:23 Bug in cmath namespace Jens Vollinga
  2006-01-30 14:27 ` John Love-Jensen
@ 2006-01-30 15:39 ` Gabriel Dos Reis
  1 sibling, 0 replies; 7+ messages in thread
From: Gabriel Dos Reis @ 2006-01-30 15:39 UTC (permalink / raw)
  To: Jens Vollinga; +Cc: gcc-help

"Jens Vollinga" <vollinga@gmx.de> writes:

| Hi,
| 
| I want to define classes called sin,cos,etc. and include the cmath header at
| the same time.

Although GCC is wrong in the behaviour, it is one that is hard to fix
and probably won't be fixed.  
furthermore, I believe your program would have violated a C++ standard
rule 17.4.3.1 (entire sub-section).

-- Gaby


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-01-30 15:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-30 14:23 Bug in cmath namespace Jens Vollinga
2006-01-30 14:27 ` John Love-Jensen
2006-01-30 14:49   ` Jens Vollinga
2006-01-30 14:57     ` John Love-Jensen
2006-01-30 14:57     ` random
2006-01-30 15:10       ` Jens Vollinga
2006-01-30 15:39 ` Gabriel Dos Reis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).