Bug 27255 - Including C++ header declares C functions
Summary: Including C++ header declares C functions
Status: RESOLVED DUPLICATE of bug 6257
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-22 02:06 UTC by Trent Michael Gamblin
Modified: 2006-04-22 08:27 UTC (History)
15 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Trent Michael Gamblin 2006-04-22 02:06:19 UTC
Including any C++ header puts all C functions in the global namespace. This code compiles and runs without errors or warnings:

#include <iostream>

int main(void)
{
  printf("test\n");
}
Comment 1 Andrew Pinski 2006-04-22 02:09:30 UTC
Two things, first this is a dup of PR 6257 (which is one of the most report bugs and that means is on http://gcc.gnu.org/bugzilla/duplicates.cgi, please next time read that list).

Second, this might become valid to do, see:
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#456

Which is an open defect agains the standard.

*** This bug has been marked as a duplicate of 6257 ***
Comment 2 Trent Michael Gamblin 2006-04-22 03:23:20 UTC
Subject: RE:  Including C++ header declares C functions

>Two things, first this is a dup of PR 6257 (which is one of the most report
>bugs and that means is on http://gcc.gnu.org/bugzilla/duplicates.cgi, 
>please
>next time read that list).
>
>Second, this might become valid to do, see:
>http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#456
>
>Which is an open defect agains the standard.

I don't think this is the same bug. I can see how including <cstdio> would 
declare printf but why in the world would including <iostream> or <vector> 
declare printf, strcpy, etc. Again, this is the code:

#include <vector>
int main(void)
{
  printf("test\n");
}

I didn't include any C headers at all. If I comment out the include 
statement GCC complains as it should. Please respond if you still think this 
is the same issue as bug 6257. Thanks for your time.

_________________________________________________________________
Powerful Parental Controls Let your child discover the best the Internet has 
to offer.  
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines 
  Start enjoying all the benefits of MSN® Premium right now and get the 
first two months FREE*.

Comment 3 Paolo Carlini 2006-04-22 08:27:43 UTC
(In reply to comment #2)
> I don't think this is the same bug. I can see how including <cstdio> would 
> declare printf but why in the world would including <iostream> or <vector> 
> declare printf, strcpy, etc.

This is definitely allowed by the Standard. It's the same bug.