Inexplicable error with std::string

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

    Inexplicable error with std::string

    Can anybody tell me why the code below should produce the error below? I'm
    going nuts here! Am I missing something incredibly obvious and simple?

    std::string::si ze_type idx;
    std::string one_line;
    ..
    ..
    ..
    idx = one_line.find(' \t', 0);


    error C2059: syntax error : 'constant'


  • John Carson

    #2
    Re: Inexplicable error with std::string

    "Dave" <better_cs_now@ yahoo.com> wrote in message
    news:vv5k40s83a vkde@news.super news.com[color=blue]
    > Can anybody tell me why the code below should produce the error
    > below? I'm going nuts here! Am I missing something incredibly obvious
    > and simple?
    >
    > std::string::si ze_type idx;
    > std::string one_line;
    > .
    > .
    > .
    > idx = one_line.find(' \t', 0);
    >
    >
    > error C2059: syntax error : 'constant'[/color]


    Try supplying a complete compileable sample that produces the error. The
    three lines you have supplied compile fine with both VC++ 2002 and Comeau
    online.


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)

    Comment

    • Dave

      #3
      Re: Inexplicable error with std::string


      "John Carson" <donaldquixote@ datafast.net.au > wrote in message
      news:3ff2d802@u senet.per.parad ox.net.au...[color=blue]
      > "Dave" <better_cs_now@ yahoo.com> wrote in message
      > news:vv5k40s83a vkde@news.super news.com[color=green]
      > > Can anybody tell me why the code below should produce the error
      > > below? I'm going nuts here! Am I missing something incredibly obvious
      > > and simple?
      > >
      > > std::string::si ze_type idx;
      > > std::string one_line;
      > > .
      > > .
      > > .
      > > idx = one_line.find(' \t', 0);
      > >
      > >
      > > error C2059: syntax error : 'constant'[/color]
      >
      >
      > Try supplying a complete compileable sample that produces the error. The
      > three lines you have supplied compile fine with both VC++ 2002 and Comeau
      > online.
      >
      >
      > --
      > John Carson
      > 1. To reply to email address, remove donald
      > 2. Don't reply to email address (post here instead)
      >[/color]

      I don't know if this will help, but here's the full function. However, to
      provide enough context to make it fully compileable would draw in thousands
      of lines of code. So, this is the best I can do, but I understand if it's
      not enough context and doesn't help... (BTW my platform is VC++ 7.1, but I
      suppose that shouldn't matter; famous last words...)

      void Sell::ChangeSal e()
      {
      std::string::si ze_type first_char;
      std::string::si ze_type idx;
      std::string::si ze_type last_char;
      int num_tabs;
      std::string one_line;
      std::string percent;
      int total(0);

      for (int i = 0; i < mVisibleMatchUp s_psxListBox->count(); ++i)
      {
      one_line = std::string(mVi sibleMatchUps_p sxListBox->text(i));
      num_tabs = std::count(one_ line.begin(), one_line.end(), '\t');

      if (num_tabs < 7)
      continue;

      idx = one_line.find(' \t', 0);
      first_char = idx + 1;
      last_char = one_line.find(' \t', first_char) - 1;

      if (last_char < first_char)
      continue;

      percent = one_line.substr (first_char, last_char - first_char + 1);
      total += atoi(percent.c_ str());

      }

      mVisibleMatchUp s_psxListBox->storeData() ;
      DeleteSale() ;
      AddSale() ;
      }//ChangeSale(...


      Comment

      • Ron Natalie

        #4
        Re: Inexplicable error with std::string


        "Dave" <better_cs_now@ yahoo.com> wrote in message news:vv5k40s83a vkde@news.super news.com...
        ]> .[color=blue]
        > idx = one_line.find(' \t', 0);
        >[/color]
        Try sticking an #undef find before this line. The line looks fine, could be some joker
        redefined find.

        Comment

        • Dave

          #5
          Re: Inexplicable error with std::string


          "Ron Natalie" <ron@sensor.com > wrote in message
          news:3ff2e06d$0 $66043$9a6e19ea @news.newshosti ng.com...[color=blue]
          >
          > "Dave" <better_cs_now@ yahoo.com> wrote in message[/color]
          news:vv5k40s83a vkde@news.super news.com...[color=blue]
          > ]> .[color=green]
          > > idx = one_line.find(' \t', 0);
          > >[/color]
          > Try sticking an #undef find before this line. The line looks fine,[/color]
          could be some joker[color=blue]
          > redefined find.
          >[/color]

          $%&#^!*#$#*!$& (repeat 100 times)!!!!!

          That actually was the problem! Man, I could just scream trying to maintain
          the code base for the project I'm on. This is the most God-awful piece of
          programming I've ever seen, and there are 300,000 lines of this nonsense!
          The programmers that did this and the managers that allowed this and
          everything else that's wrong with this app. to happen should all be
          summarily executed...

          Thanks, I think you just saved my sanity! (But it's doomed eventually anyway
          since I'll have to continue to work on this project!)


          Comment

          • Cy Edmunds

            #6
            Re: Inexplicable error with std::string

            "Dave" <better_cs_now@ yahoo.com> wrote in message
            news:vv5ojpbili b253@news.super news.com...[color=blue]
            >
            > "Ron Natalie" <ron@sensor.com > wrote in message
            > news:3ff2e06d$0 $66043$9a6e19ea @news.newshosti ng.com...[color=green]
            > >
            > > "Dave" <better_cs_now@ yahoo.com> wrote in message[/color]
            > news:vv5k40s83a vkde@news.super news.com...[color=green]
            > > ]> .[color=darkred]
            > > > idx = one_line.find(' \t', 0);
            > > >[/color]
            > > Try sticking an #undef find before this line. The line looks fine,[/color]
            > could be some joker[color=green]
            > > redefined find.
            > >[/color]
            >
            > $%&#^!*#$#*!$& (repeat 100 times)!!!!!
            >
            > That actually was the problem! Man, I could just scream trying to maintain
            > the code base for the project I'm on. This is the most God-awful piece of
            > programming I've ever seen, and there are 300,000 lines of this nonsense!
            > The programmers that did this and the managers that allowed this and
            > everything else that's wrong with this app. to happen should all be
            > summarily executed...
            >
            > Thanks, I think you just saved my sanity! (But it's doomed eventually[/color]
            anyway[color=blue]
            > since I'll have to continue to work on this project!)
            >
            >[/color]

            Ron made a great call here. It goes to show you why I hate C macros so much.
            As BS once commented, they make what the compiler sees different from what
            you see. How can that be good?

            --
            Cy



            Comment

            • Jeff Schwab

              #7
              Re: Inexplicable error with std::string

              Dave wrote:[color=blue]
              > "Ron Natalie" <ron@sensor.com > wrote
              >[color=green]
              >>"Dave" <better_cs_now@ yahoo.com> wrote[color=darkred]
              >>>idx = one_line.find(' \t', 0);[/color]
              >>
              >>Try sticking an #undef find before this line. The line looks fine,
              >>could be some joker redefined find.[/color][/color]
              [color=blue]
              > $%&#^!*#$#*!$& (repeat 100 times)!!!!!
              >
              > That actually was the problem![/color]

              Okay, *that's* impressive.

              Ron, are you actually the author of the dubious code in question?

              ;),
              Jeff

              Comment

              • P.J. Plauger

                #8
                Re: Inexplicable error with std::string

                "Cy Edmunds" <cedmunds@spaml ess.rochester.r r.com> wrote in message
                news:DJCIb.9677 8$JW3.88024@twi ster.nyroc.rr.c om...
                [color=blue]
                > Ron made a great call here. It goes to show you why I hate C macros so[/color]
                much.[color=blue]
                > As BS once commented, they make what the compiler sees different from what
                > you see. How can that be good?[/color]

                Maybe the compiler doesn't recognize the same dialect that you want
                to speak. I agree that macros can be abused, and the OP has presented
                an extreme case of such abuse. But the irony is that C++ has spawned
                so many dialects over the past decade that implementors *must* make
                extensive use of the preprocessor to cope.

                P.J. Plauger
                Dinkumware, Ltd.



                Comment

                • Ron Natalie

                  #9
                  Re: Inexplicable error with std::string


                  "Jeff Schwab" <jeffplus@comca st.net> wrote in message news:6dCdnbEUvb Nlnm6iRVn-tw@comcast.com. ..[color=blue]
                  > Dave wrote:[color=green]
                  > > "Ron Natalie" <ron@sensor.com > wrote
                  > >[color=darkred]
                  > >>"Dave" <better_cs_now@ yahoo.com> wrote
                  > >>>idx = one_line.find(' \t', 0);
                  > >>
                  > >>Try sticking an #undef find before this line. The line looks fine,
                  > >>could be some joker redefined find.[/color][/color]
                  >[color=green]
                  > > $%&#^!*#$#*!$& (repeat 100 times)!!!!!
                  > >
                  > > That actually was the problem![/color]
                  >
                  > Okay, *that's* impressive.
                  >
                  > Ron, are you actually the author of the dubious code in question?[/color]

                  Nope, I looked up the error in the Microsoft docs. Then I thought about how the
                  above syntax could gag on the '\t' or 0 literals and the only way I could think of was
                  if find() were NOT a function.

                  Comment

                  • Cy Edmunds

                    #10
                    Re: Inexplicable error with std::string

                    "P.J. Plauger" <pjp@dinkumware .com> wrote in message
                    news:UHDIb.3344 4$E17.15305@nwr ddc02.gnilink.n et...[color=blue]
                    > "Cy Edmunds" <cedmunds@spaml ess.rochester.r r.com> wrote in message
                    > news:DJCIb.9677 8$JW3.88024@twi ster.nyroc.rr.c om...
                    >[color=green]
                    > > Ron made a great call here. It goes to show you why I hate C macros so[/color]
                    > much.[color=green]
                    > > As BS once commented, they make what the compiler sees different from[/color][/color]
                    what[color=blue][color=green]
                    > > you see. How can that be good?[/color]
                    >
                    > Maybe the compiler doesn't recognize the same dialect that you want
                    > to speak. I agree that macros can be abused, and the OP has presented
                    > an extreme case of such abuse. But the irony is that C++ has spawned
                    > so many dialects over the past decade that implementors *must* make
                    > extensive use of the preprocessor to cope.
                    >
                    > P.J. Plauger
                    > Dinkumware, Ltd.
                    > http://www.dinkumware.com
                    >
                    >[/color]

                    Absolutely no argument here.

                    --
                    Cy



                    Comment

                    • Jeff Schwab

                      #11
                      Re: Inexplicable error with std::string

                      Cy Edmunds wrote:[color=blue]
                      > "P.J. Plauger" <pjp@dinkumware .com> wrote in message
                      > news:UHDIb.3344 4$E17.15305@nwr ddc02.gnilink.n et...
                      >[color=green]
                      >>"Cy Edmunds" <cedmunds@spaml ess.rochester.r r.com> wrote in message
                      >>news:DJCIb.96 778$JW3.88024@t wister.nyroc.rr .com...
                      >>
                      >>[color=darkred]
                      >>>Ron made a great call here. It goes to show you why I hate C macros so
                      >>>much.[/color]
                      >>[color=darkred]
                      >>>As BS once commented, they make what the compiler sees different from
                      >>>what you see. How can that be good?[/color]
                      >>
                      >>Maybe the compiler doesn't recognize the same dialect that you want
                      >>to speak. I agree that macros can be abused, and the OP has presented
                      >>an extreme case of such abuse. But the irony is that C++ has spawned
                      >>so many dialects over the past decade that implementors *must* make
                      >>extensive use of the preprocessor to cope.
                      >>
                      >>P.J. Plauger
                      >>Dinkumware, Ltd.
                      >>http://www.dinkumware.com
                      >>
                      >>[/color]
                      >
                      >
                      > Absolutely no argument here.
                      >[/color]

                      I didn't realize the situation was that bad. I'm sure this is a
                      hopelessly naive question, but... What's wrong with complying (as
                      closely as possible) with the most recent standard, and providing flags
                      for compatibility with the most common dialects?

                      Comment

                      • Cy Edmunds

                        #12
                        Re: Inexplicable error with std::string

                        "Jeff Schwab" <jeffplus@comca st.net> wrote in message
                        news:jLOdnbJfgN rW6m6i4p2dnA@co mcast.com...[color=blue]
                        > Cy Edmunds wrote:[color=green]
                        > > "P.J. Plauger" <pjp@dinkumware .com> wrote in message
                        > > news:UHDIb.3344 4$E17.15305@nwr ddc02.gnilink.n et...
                        > >[color=darkred]
                        > >>"Cy Edmunds" <cedmunds@spaml ess.rochester.r r.com> wrote in message
                        > >>news:DJCIb.96 778$JW3.88024@t wister.nyroc.rr .com...
                        > >>
                        > >>
                        > >>>Ron made a great call here. It goes to show you why I hate C macros so
                        > >>>much.
                        > >>
                        > >>>As BS once commented, they make what the compiler sees different from
                        > >>>what you see. How can that be good?
                        > >>
                        > >>Maybe the compiler doesn't recognize the same dialect that you want
                        > >>to speak. I agree that macros can be abused, and the OP has presented
                        > >>an extreme case of such abuse. But the irony is that C++ has spawned
                        > >>so many dialects over the past decade that implementors *must* make
                        > >>extensive use of the preprocessor to cope.
                        > >>
                        > >>P.J. Plauger
                        > >>Dinkumware, Ltd.
                        > >>http://www.dinkumware.com
                        > >>
                        > >>[/color]
                        > >
                        > >
                        > > Absolutely no argument here.
                        > >[/color]
                        >
                        > I didn't realize the situation was that bad. I'm sure this is a
                        > hopelessly naive question, but... What's wrong with complying (as
                        > closely as possible) with the most recent standard, and providing flags
                        > for compatibility with the most common dialects?
                        >[/color]

                        Nothing, if that's all there was to it. Check out the macro spaghetti at the
                        top of various library code (standard library, boost, etc.) and see what
                        these poor guys have to put up with in order to get their code to compile
                        across platforms and compilers. It's brutal.

                        I'm opposed to the preprocessor if there is any reasonable alternative but
                        you do what you gotta do...

                        --
                        Cy



                        Comment

                        • Jeff Schwab

                          #13
                          Re: Inexplicable error with std::string

                          Cy Edmunds wrote:[color=blue]
                          > "Jeff Schwab" <jeffplus@comca st.net> wrote in message
                          > news:jLOdnbJfgN rW6m6i4p2dnA@co mcast.com...
                          >[color=green]
                          >>Cy Edmunds wrote:
                          >>[color=darkred]
                          >>>"P.J. Plauger" <pjp@dinkumware .com> wrote in message
                          >>>news:UHDIb.3 3444$E17.15305@ nwrddc02.gnilin k.net...
                          >>>
                          >>>
                          >>>>"Cy Edmunds" <cedmunds@spaml ess.rochester.r r.com> wrote in message
                          >>>>news:DJCIb. 96778$JW3.88024 @twister.nyroc. rr.com...
                          >>>>
                          >>>>
                          >>>>
                          >>>>>Ron made a great call here. It goes to show you why I hate C macros so
                          >>>>>much.
                          >>>>
                          >>>>>As BS once commented, they make what the compiler sees different from
                          >>>>>what you see. How can that be good?
                          >>>>
                          >>>>Maybe the compiler doesn't recognize the same dialect that you want
                          >>>>to speak. I agree that macros can be abused, and the OP has presented
                          >>>>an extreme case of such abuse. But the irony is that C++ has spawned
                          >>>>so many dialects over the past decade that implementors *must* make
                          >>>>extensive use of the preprocessor to cope.
                          >>>>
                          >>>>P.J. Plauger
                          >>>>Dinkumwar e, Ltd.
                          >>>>http://www.dinkumware.com
                          >>>>
                          >>>>
                          >>>
                          >>>
                          >>>Absolutely no argument here.
                          >>>[/color]
                          >>
                          >>I didn't realize the situation was that bad. I'm sure this is a
                          >>hopelessly naive question, but... What's wrong with complying (as
                          >>closely as possible) with the most recent standard, and providing flags
                          >>for compatibility with the most common dialects?
                          >>[/color]
                          >
                          >
                          > Nothing, if that's all there was to it. Check out the macro spaghetti at the
                          > top of various library code (standard library, boost, etc.) and see what
                          > these poor guys have to put up with in order to get their code to compile
                          > across platforms and compilers. It's brutal.
                          >
                          > I'm opposed to the preprocessor if there is any reasonable alternative but
                          > you do what you gotta do...[/color]

                          I see what you mean. So, the problem isn't so much with dialects of
                          C++, but with portability across platforms?


                          Comment

                          • Cy Edmunds

                            #14
                            Re: Inexplicable error with std::string

                            "Jeff Schwab" <jeffplus@comca st.net> wrote in message
                            news:lN6dnUrNr8 VADW6iRVn-tw@comcast.com. ..[color=blue]
                            > Cy Edmunds wrote:[color=green]
                            > > "Jeff Schwab" <jeffplus@comca st.net> wrote in message
                            > > news:jLOdnbJfgN rW6m6i4p2dnA@co mcast.com...
                            > >[color=darkred]
                            > >>Cy Edmunds wrote:
                            > >>
                            > >>>"P.J. Plauger" <pjp@dinkumware .com> wrote in message
                            > >>>news:UHDIb.3 3444$E17.15305@ nwrddc02.gnilin k.net...
                            > >>>
                            > >>>
                            > >>>>"Cy Edmunds" <cedmunds@spaml ess.rochester.r r.com> wrote in message
                            > >>>>news:DJCIb. 96778$JW3.88024 @twister.nyroc. rr.com...
                            > >>>>
                            > >>>>
                            > >>>>
                            > >>>>>Ron made a great call here. It goes to show you why I hate C macros[/color][/color][/color]
                            so[color=blue][color=green][color=darkred]
                            > >>>>>much.
                            > >>>>
                            > >>>>>As BS once commented, they make what the compiler sees different from
                            > >>>>>what you see. How can that be good?
                            > >>>>
                            > >>>>Maybe the compiler doesn't recognize the same dialect that you want
                            > >>>>to speak. I agree that macros can be abused, and the OP has presented
                            > >>>>an extreme case of such abuse. But the irony is that C++ has spawned
                            > >>>>so many dialects over the past decade that implementors *must* make
                            > >>>>extensive use of the preprocessor to cope.
                            > >>>>
                            > >>>>P.J. Plauger
                            > >>>>Dinkumwar e, Ltd.
                            > >>>>http://www.dinkumware.com
                            > >>>>
                            > >>>>
                            > >>>
                            > >>>
                            > >>>Absolutely no argument here.
                            > >>>
                            > >>
                            > >>I didn't realize the situation was that bad. I'm sure this is a
                            > >>hopelessly naive question, but... What's wrong with complying (as
                            > >>closely as possible) with the most recent standard, and providing flags
                            > >>for compatibility with the most common dialects?
                            > >>[/color]
                            > >
                            > >
                            > > Nothing, if that's all there was to it. Check out the macro spaghetti at[/color][/color]
                            the[color=blue][color=green]
                            > > top of various library code (standard library, boost, etc.) and see what
                            > > these poor guys have to put up with in order to get their code to[/color][/color]
                            compile[color=blue][color=green]
                            > > across platforms and compilers. It's brutal.
                            > >
                            > > I'm opposed to the preprocessor if there is any reasonable alternative[/color][/color]
                            but[color=blue][color=green]
                            > > you do what you gotta do...[/color]
                            >
                            > I see what you mean. So, the problem isn't so much with dialects of
                            > C++, but with portability across platforms?
                            >
                            >[/color]

                            That and compilers, which have far more "personalit y" than the standard
                            allows. :) I guess that counts as dialects. There are other problems too,
                            like calling sequences, various non-standard declarations required to
                            compile DLL's, mumble mumble ...

                            I'm the wrong guy to ask though. My job doesn't really require me to get my
                            code to compile across a lot of platforms and compilers. It's guys like PJ
                            who bear the brunt of these problems.

                            --
                            Cy



                            Comment

                            Working...