order of includes?

Noel Yap noel.yap@gmail.com
Sun Jan 8 19:21:00 GMT 2006


If iostream has such a check then it shouldn't matter which order the
#includes occur whichi is why I suspect at least some part of it may
not be guarded.  I still think this scenario is unlikely and that the
most likely culprit is a name clash somewhere.

I don't know of an easy way to find name clashes.  What I've done in
the past is to make as good a guess as I could and change that name to
see if there's any effect.

Noel
On 1/8/06, Blake Huff <stangmechanic@gmail.com> wrote:
> All:
>
> Doesn't <iostream>  have a check so that it is only included once?
> I'd imagine that the following example compiles fine:
>
> #include<a_header_that_includes_iostream.h>
> #include<iostream>
>
>
> but
>
> #include<iostream>
> #include<a_header_that_includes_iostream.h>
>
>
> wouldn't work, unless the non-standard header does the same check to
> see if  iostream has already been included....
>
> Thoughts?
>
>
> Blake
>
>
>
>
> On Jan 8, 2006, at 12:09 PM, Noel Yap wrote:
>
> > I _think_ iostream does some tricks (the nifty counter?) in order to
> > properly statically initialize cin, cout, and cerr so strange things
> > might occur if it's included twice although this sounds highly
> > unlikely.  In any case, it's usually better to include iosfwd in your
> > header files rather than iostream.
> >
> > Noel
> >
> > On 1/8/06, Brian Budge <brian.budge@gmail.com> wrote:
> >> Yeah, the funny thing is, the first thing included in my library
> >> (tracing all the includes back depth first), is <iostream>.  So in
> >> this particular example, I don't really even need to #include
> >> <iostream>... and in fact, when I don't, everything compiles great.
> >>
> >> Any suggestions on how to find such a name clash?
> >>
> >> Thanks,
> >>   Brian
> >>
> >> On 1/8/06, Noel Yap <noel.yap@gmail.com> wrote:
> >>> Forcing users to #include in a specific order makes your code less
> >>> usable.  Try investigating what exactly is causing the error.  Since
> >>> iostream is a standard header file that shouldn't be depending upon
> >>> anything in your header file, there's probably a name clash
> >>> somewhere.
> >>>
> >>> Noel
> >>> On 1/8/06, Brian Budge <brian.budge@gmail.com> wrote:
> >>>> It turned out to be that I needed to change
> >>>>
> >>>> #include <iostream>
> >>>> #include <subdiv_shellmap.h>
> >>>>
> >>>> to
> >>>>
> >>>> #include <subdiv_shellmap.h>
> >>>> #include <iostream>
> >>>>
> >>>> Thanks,
> >>>>   Brian
> >>>>
> >>>> On 07 Jan 2006 21:55:48 -0800, Ian Lance Taylor <ian@airs.com>
> >>>> wrote:
> >>>>> Brian Budge <brian.budge@gmail.com> writes:
> >>>>>
> >>>>>> I am getting the following error:
> >>>>>>
> >>>>>> error: expected `,' or `...' before numeric constant
> >>>>>>
> >>>>>> The code is trivial, and has been successfully used before.
> >>>>>> It is
> >>>>>> from a template library I wrote.
> >>>>>>
> >>>>>> From searching google, I get the impression that it could be from
> >>>>>> #including things in the "wrong" order.  Could this be the case?
> >>>>>
> >>>>> It's very unlikely.
> >>>>>
> >>>>>> Anybody have any tips or tricks for narrowing down the problem
> >>>>>> here?
> >>>>>
> >>>>> Look closely at the source code.  If that doesn't help, run the
> >>>>> compile with --save-temps, and look at the relevant line in
> >>>>> the .i (if
> >>>>> C) or .ii (if C++) file.
> >>>>>
> >>>>> (Please don't reply to me personally; thanks.)
> >>>>>
> >>>>> Ian
> >>>>>
> >>>>
> >>>>
> >>>
> >>
> >
>
> Blake Huff
> stangmechanic@gmail.com
>
>
>
>
>



More information about the Gcc-help mailing list