C and C++ naming issues?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Noah Roberts

    C and C++ naming issues?



    That page contains a header that when included does not define any of
    the typedefs or any of the value references that are in that file. For
    instance, I included that file and then tried this:

    switch (file.get_type( "valid_operatin g_systems"))
    {
    case CFG_ITEM_NONE: cerr << "NONE" << endl; break;
    case CFG_ITEM_INTEGE R: cerr << "INT" << endl; break;
    case CFG_ITEM_BOOLEA N: cerr << "BOOL" << endl; break;
    case CFG_ITEM_FLOATI NGPOINT: cerr << "FLOAT" << endl; break;
    case CFG_ITEM_STRING : cerr << "STR" << endl; break;
    case CFG_ITEM_CONTAI NER: cerr << "CONTAINER" << endl; break;
    default: cerr << "WHO THE FUCK KNOWS?!" << endl;
    }

    When compiled with g++ I get an error saying that none of those
    identifiers exist. But they are quite obviously defined right there in
    the file I included! If I copy the definition for CfgItemType into my
    source file it compiles just fine. I would really like to understand
    what the hell is going on here if anyone can figure that out.

    Thanks.

  • Victor Bazarov

    #2
    Re: C and C++ naming issues?

    Noah Roberts wrote:[color=blue]
    > http://www.gubbe.ch/code/libcfgparse...8h-source.html
    >
    > That page contains a header that when included does not define any of
    > the typedefs or any of the value references that are in that file. For
    > instance, I included that file and then tried this:
    >
    > switch (file.get_type( "valid_operatin g_systems"))
    > {
    > case CFG_ITEM_NONE: cerr << "NONE" << endl; break;
    > case CFG_ITEM_INTEGE R: cerr << "INT" << endl; break;
    > case CFG_ITEM_BOOLEA N: cerr << "BOOL" << endl; break;
    > case CFG_ITEM_FLOATI NGPOINT: cerr << "FLOAT" << endl; break;
    > case CFG_ITEM_STRING : cerr << "STR" << endl; break;
    > case CFG_ITEM_CONTAI NER: cerr << "CONTAINER" << endl; break;
    > default: cerr << "WHO THE FUCK KNOWS?!" << endl;
    > }
    >
    > When compiled with g++ I get an error saying that none of those
    > identifiers exist. But they are quite obviously defined right there in
    > the file I included! If I copy the definition for CfgItemType into my
    > source file it compiles just fine. I would really like to understand
    > what the hell is going on here if anyone can figure that out.[/color]

    I believe the answer is in the FAQ 5.8. Find the FAQ by following this
    link: http://www.parashift.com/c++-faq-lite/

    V

    Comment

    • Noah Roberts

      #3
      Re: C and C++ naming issues?


      Victor Bazarov wrote:
      [color=blue]
      > I believe the answer is in the FAQ 5.8. Find the FAQ by following[/color]
      this[color=blue]
      > link: http://www.parashift.com/c++-faq-lite/[/color]

      I don't think so, smartass.

      Comment

      • Noah Roberts

        #4
        Re: C and C++ naming issues?

        I have figured out what is going on. Thanks anyway.

        Comment

        • Ali Çehreli

          #5
          Re: C and C++ naming issues?

          "Noah Roberts" <nroberts@stmar tin.edu> wrote in message
          news:1109629051 .436206.175770@ l41g2000cwc.goo glegroups.com.. .[color=blue]
          > I have figured out what is going on. Thanks anyway.
          >[/color]

          I did spend some time trying to figure out your problem. Would you please
          let us know what it was...

          Thank you,
          Ali

          Comment

          • Victor Bazarov

            #6
            Re: C and C++ naming issues?

            Noah Roberts wrote:[color=blue]
            > Victor Bazarov wrote:
            >
            >[color=green]
            >>I believe the answer is in the FAQ 5.8. Find the FAQ by following[/color]
            >
            > this
            >[color=green]
            >>link: http://www.parashift.com/c++-faq-lite/[/color]
            >
            >
            > I don't think so, smartass.
            >[/color]

            Do they teach you that language at Saint Martin's or are you just
            naturally so sweet?

            Comment

            • Noah Roberts

              #7
              Re: C and C++ naming issues?


              Ali Çehreli wrote:[color=blue]
              > "Noah Roberts" <nroberts@stmar tin.edu> wrote in message
              > news:1109629051 .436206.175770@ l41g2000cwc.goo glegroups.com.. .[color=green]
              > > I have figured out what is going on. Thanks anyway.
              > >[/color]
              >
              > I did spend some time trying to figure out your problem. Would you[/color]
              please[color=blue]
              > let us know what it was...[/color]

              The file was being included by another file which was wrapping it in a
              namespace. When I included it after the fact the #ifdef protection of
              course kept anything in that file from being included because it
              already was...but in a namespace.

              How common is that when dealing with C++ wrapped libraries? I don't
              like it...I think there should be

              #ifdef __cplusplus
              namespace x {
              #endif

              in any file that is going to be used in C++ that should be in a
              namespace when so used.

              Thanks for trying to figure out the problem. In my opinion the problem
              was poor header design.

              I figured it out when trying to pass one of those identifiers as a
              parameter to a function that was set to accept only those values. Got
              one of these:

              test_cfg.cpp: In function `int main()':
              test_cfg.cpp:11 6: no matching function for call to
              `Cfg::Container ::Container(
              CfgContainerTyp e)'
              C:/msys/1.0/local/include/cfgparse/container.hpp:7 8: candidates are:
              ....
              C:/msys/1.0/local/include/cfgparse/container.hpp:5 7:
              Cfg::Container: :Container(Cfg: :CfgContainerTy pe)

              And that pretty much told me what was wrong.

              Comment

              • Default User

                #8
                Re: C and C++ naming issues?

                Noah Roberts wrote:
                [color=blue]
                >
                > Victor Bazarov wrote:
                >[color=green]
                > > I believe the answer is in the FAQ 5.8. Find the FAQ by following[/color]
                > this[color=green]
                > > link: http://www.parashift.com/c++-faq-lite/[/color]
                >
                > I don't think so, smartass.[/color]

                And that'll be *plonk* for you.




                Brian

                Comment

                • Raymond Martineau

                  #9
                  Re: C and C++ naming issues?

                  On 28 Feb 2005 14:16:33 -0800, "Noah Roberts" <nroberts@stmar tin.edu>
                  wrote:
                  [color=blue]
                  >
                  >Victor Bazarov wrote:
                  >[color=green]
                  >> I believe the answer is in the FAQ 5.8. Find the FAQ by following[/color]
                  >this[color=green]
                  >> link: http://www.parashift.com/c++-faq-lite/[/color]
                  >
                  >I don't think so, smartass.[/color]

                  In section 5.8:
                  [color=blue]
                  >2. Post complete code: put in all necessary #includes and declarations
                  >of needed types and functions[/color]

                  As you mentioned in another posting, you had an include file being used
                  that was wrapped in a namespace. Providing this information to the group
                  would have allowed the problem to be solved much more quickly (if it wasn't
                  solved on the spot.)


                  Comment

                  • Noah Roberts

                    #10
                    Re: C and C++ naming issues?


                    Raymond Martineau wrote:
                    [color=blue]
                    > As you mentioned in another posting, you had an include file being[/color]
                    used[color=blue]
                    > that was wrapped in a namespace. Providing this information to the[/color]
                    group[color=blue]
                    > would have allowed the problem to be solved much more quickly (if it[/color]
                    wasn't[color=blue]
                    > solved on the spot.)[/color]

                    Very well. Next time I will make sure to paste my entire program and
                    the source for all libraries and header files as well. I am sure that
                    will make it much easier to diagnose any problems.

                    Unfortunately it looks like my last post got lost. Oh well.

                    Man, you guys need something better to do. You are wound WAY too
                    tight. I just don't have the patience.

                    Comment

                    • Victor Bazarov

                      #11
                      Re: C and C++ naming issues?

                      Noah Roberts wrote:[color=blue]
                      > [..] I just don't have the patience.
                      >[/color]

                      Isn't that the real problem here?

                      Comment

                      • Larry Brasfield

                        #12
                        Re: C and C++ naming issues?

                        "Noah Roberts" <nroberts@stmar tin.edu> wrote in message
                        news:1109697706 .788794.180620@ f14g2000cwb.goo glegroups.com.. .[color=blue]
                        >
                        > Raymond Martineau wrote:
                        >[color=green]
                        >> As you mentioned in another posting, you had an include file being
                        >> used that was wrapped in a namespace. Providing this information
                        >> to the group would have allowed the problem to be solved much
                        >> more quickly (if it wasn't solved on the spot.)[/color][/color]

                        Quite true and good input at this point.
                        [color=blue]
                        > Very well. Next time I will make sure to paste my entire program and
                        > the source for all libraries and header files as well. I am sure that
                        > will make it much easier to diagnose any problems.[/color]

                        Please try to suppress your more juvenile responses
                        and consider why the expectations here differ from
                        what you have done. It is a mistake to think of this
                        forum as simply a free help center.

                        People are commonly asked to provide a minimal
                        but complete program that demonstrates the problem
                        they are asking about. If you had done this, you could
                        have found your problem without posting anything.
                        Posting a whole, unreduced project will lead only to
                        some wasted storage and time. And it tells those who
                        might help you that you are not interested in helping to
                        solve your own problem. When I see that, my interest
                        dwindles rapidly to none.
                        [color=blue]
                        > Unfortunately it looks like my last post got lost. Oh well.[/color]

                        As far as I can see, this has about as much meaning to
                        the other participants here as if you had announced
                        that you once had an itch and got it scratched.
                        [color=blue]
                        > Man, you guys need something better to do. You are wound
                        > WAY too tight. I just don't have the patience.[/color]

                        If you continue on your present trend, you are
                        likely to find that the feeling has become mutual.

                        --
                        --Larry Brasfield
                        email: donotspam_larry _brasfield@hotm ail.com
                        Above views may belong only to me.


                        Comment

                        • Noah Roberts

                          #13
                          Re: C and C++ naming issues?


                          Larry Brasfield wrote:
                          It is a mistake to think of this[color=blue]
                          > forum as simply a free help center.[/color]

                          I have frequented this particular newsgroup for many years. I know
                          what it is. Thanks anyway.

                          Comment

                          • Ben Hetland

                            #14
                            Re: C and C++ naming issues?

                            Noah Roberts wrote:
                            [color=blue]
                            > How common is that when dealing with C++ wrapped libraries? I don't
                            > like it...I think there should be
                            >
                            > #ifdef __cplusplus
                            > namespace x {
                            > #endif
                            >
                            > in any file that is going to be used in C++ that should be in a
                            > namespace when so used.[/color]

                            Doesn't sound like a good idea to me. It should often be the _user_ of
                            such a library that needs to distinguish between the different libraries
                            used when they share some common names or definitions. Otherwise, what
                            if two library creators both decide to use the same namespace, and
                            happen to also collide on some identifier names?

                            IMHO, much better when I can say something like this in my code:

                            -----
                            namespace win32 {
                            #include <windows.h>
                            }
                            namespace mailer {
                            #include "somevendor .h"
                            }

                            ::
                            win32::PostMess age(wnd_handle, mymsg, 1, 5);
                            mailer::PostMes sage(recipient, mymsg, 1, 5);
                            -----

                            --
                            -+-Ben-+-

                            Comment

                            Working...