Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. Who finds it first... [closed] : [modified]

Who finds it first... [closed] : [modified]

Scheduled Pinned Locked Moved Clever Code
comhelp
23 Posts 10 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Eytukan

    Ah good optimus! You've spotted the logical mistake I did when I put that code here and modified online. Sorry I've corrected the mistake. Look at the code again, you'd see it. Also check my reply to Vikram. Anyway you are dangerously close the bug! good luck :-D


    Best wishes to Rexx[^]

    O Offline
    O Offline
    Optimus Chaos
    wrote on last edited by
    #6

    I'm not sure but doesn't push_back already take a reference while you are passing a pointer to it?

    E 1 Reply Last reply
    0
    • O Optimus Chaos

      I'm not sure but doesn't push_back already take a reference while you are passing a pointer to it?

      E Offline
      E Offline
      Eytukan
      wrote on last edited by
      #7

      Hey no,k now I'm pushing the string's value inside the vector , no refs... So ignore it ;).. find the bug.. just a clue. It's related to std::strings. :-D


      Best wishes to Rexx[^]

      O 1 Reply Last reply
      0
      • E Eytukan

        Hey no,k now I'm pushing the string's value inside the vector , no refs... So ignore it ;).. find the bug.. just a clue. It's related to std::strings. :-D


        Best wishes to Rexx[^]

        O Offline
        O Offline
        Optimus Chaos
        wrote on last edited by
        #8

        Never worked that much with std::string but I will keep track :-D

        1 Reply Last reply
        0
        • E Eytukan

          std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } } Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.


          Best wishes to Rexx[^]

          A Offline
          A Offline
          Atara
          wrote on last edited by
          #9

          if(stSourcePath && stDestPath && (stSourcePath.size==0)||(stDestPath.size==0)) ???

          Atara

          1 Reply Last reply
          0
          • E Eytukan

            std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } } Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.


            Best wishes to Rexx[^]

            S Offline
            S Offline
            sw thi
            wrote on last edited by
            #10

            if((stSourcePath.size==0)||(stDestPath.size==0)) Isn't size a function?? It should probably be if((stSourcePath.size()==0)||(stDestPath.size()==0)) and you should be getting a compilation error?!!

            "a child will grow up to become an adult, but you can never stop the adult from acting like a child"

            E 1 Reply Last reply
            0
            • E Eytukan

              std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } } Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.


              Best wishes to Rexx[^]

              A Offline
              A Offline
              admirm
              wrote on last edited by
              #11

              **std::string stSroucePath;** std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0)) stSroucePath ... it should be stSourcePath ... it is a typo? Em i right? -- modified at 5:42 Tuesday 17th July, 2007

              E M 3 Replies Last reply
              0
              • S sw thi

                if((stSourcePath.size==0)||(stDestPath.size==0)) Isn't size a function?? It should probably be if((stSourcePath.size()==0)||(stDestPath.size()==0)) and you should be getting a compilation error?!!

                "a child will grow up to become an adult, but you can never stop the adult from acting like a child"

                E Offline
                E Offline
                Eytukan
                wrote on last edited by
                #12

                You get my gift :beer:.


                Best wishes to Rexx[^]

                V 1 Reply Last reply
                0
                • A admirm

                  **std::string stSroucePath;** std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0)) stSroucePath ... it should be stSourcePath ... it is a typo? Em i right? -- modified at 5:42 Tuesday 17th July, 2007

                  E Offline
                  E Offline
                  Eytukan
                  wrote on last edited by
                  #13

                  Oh my god just realizing how bad I'm with the keyboard. Sorry for the typo dude. btw, Swati m just found it! It's the simple "()" thingie.


                  Best wishes to Rexx[^]

                  1 Reply Last reply
                  0
                  • A admirm

                    **std::string stSroucePath;** std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0)) stSroucePath ... it should be stSourcePath ... it is a typo? Em i right? -- modified at 5:42 Tuesday 17th July, 2007

                    E Offline
                    E Offline
                    Eytukan
                    wrote on last edited by
                    #14

                    Anyway you've spotted a typo bug, so :beer: for ya too ! :-D


                    Best wishes to Rexx[^]

                    1 Reply Last reply
                    0
                    • E Eytukan

                      You get my gift :beer:.


                      Best wishes to Rexx[^]

                      V Offline
                      V Offline
                      Vikram A Punathambekar
                      wrote on last edited by
                      #15

                      Hey, I saw that! I was fairly sure it was C++, but noticed size didn't have the parantheses. That's why I said the language looks alien. I was looking for a runtime error. :| But Swathi can have your beer; I'm a teetotaller. ;P

                      Cheers, Vıkram.


                      After all is said and done, much is said and little is done.

                      S E 2 Replies Last reply
                      0
                      • V Vikram A Punathambekar

                        Hey, I saw that! I was fairly sure it was C++, but noticed size didn't have the parantheses. That's why I said the language looks alien. I was looking for a runtime error. :| But Swathi can have your beer; I'm a teetotaller. ;P

                        Cheers, Vıkram.


                        After all is said and done, much is said and little is done.

                        S Offline
                        S Offline
                        sw thi
                        wrote on last edited by
                        #16

                        He mentioned that it was a typo ;p

                        "a child will grow up to become an adult, but you can never stop the adult from acting like a child"

                        1 Reply Last reply
                        0
                        • V Vikram A Punathambekar

                          Hey, I saw that! I was fairly sure it was C++, but noticed size didn't have the parantheses. That's why I said the language looks alien. I was looking for a runtime error. :| But Swathi can have your beer; I'm a teetotaller. ;P

                          Cheers, Vıkram.


                          After all is said and done, much is said and little is done.

                          E Offline
                          E Offline
                          Eytukan
                          wrote on last edited by
                          #17

                          There are many objects that expose values through member variables, so when you mix them up with the objects that uses functions to return values, you'll get confused. In particular when the object supports both ways.

                          Vikram A Punathambekar wrote:

                          But Swathi can have your beer; I'm a teetotaller.

                          Hey that's actually an apple juice filled in a beer cup ;P


                          Best wishes to Rexx[^]

                          1 Reply Last reply
                          0
                          • A admirm

                            **std::string stSroucePath;** std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0)) stSroucePath ... it should be stSourcePath ... it is a typo? Em i right? -- modified at 5:42 Tuesday 17th July, 2007

                            M Offline
                            M Offline
                            mav northwind
                            wrote on last edited by
                            #18

                            admirm wrote:

                            stSroucePath ... it should be stSourcePath ... it is a typo? Em i right?

                            says the guy with a typo in his user name - shouldn't it be admin? :laugh:

                            Regards, mav -- Black holes are the places where God divided by 0...

                            1 Reply Last reply
                            0
                            • E Eytukan

                              std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } } Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.


                              Best wishes to Rexx[^]

                              M Offline
                              M Offline
                              Michael Sadlon
                              wrote on last edited by
                              #19

                              That's why I use std::string.length :) (or was it length() :doh:)

                              1 Reply Last reply
                              0
                              • E Eytukan

                                std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } } Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.


                                Best wishes to Rexx[^]

                                D Offline
                                D Offline
                                dighn
                                wrote on last edited by
                                #20

                                How does stSourcePath.size==0 even compile?! Also, is something wrong here: vec_stMovedFiles.push_back(&stDestPath); return; You are storing the address of a stack variable followed immediately by a return. The use of the variable must be after the return, at which point the variable is no longer valid.

                                E N 3 Replies Last reply
                                0
                                • D dighn

                                  How does stSourcePath.size==0 even compile?! Also, is something wrong here: vec_stMovedFiles.push_back(&stDestPath); return; You are storing the address of a stack variable followed immediately by a return. The use of the variable must be after the return, at which point the variable is no longer valid.

                                  E Offline
                                  E Offline
                                  Eytukan
                                  wrote on last edited by
                                  #21

                                  Please check my reply to Optimus Chaos Linkety[^] actually I modified/typed the code here online just to make it simpler to understand. I just copied the string name from the previous line, so the "&" thing came along!

                                  dighn wrote:

                                  You are storing the address of a stack variable followed immediately by a return. The use of the variable must be after the return, at which point the variable is no longer valid.

                                  Yup I know :). The reason just explained above.


                                  Best wishes to Rexx[^]

                                  1 Reply Last reply
                                  0
                                  • D dighn

                                    How does stSourcePath.size==0 even compile?! Also, is something wrong here: vec_stMovedFiles.push_back(&stDestPath); return; You are storing the address of a stack variable followed immediately by a return. The use of the variable must be after the return, at which point the variable is no longer valid.

                                    E Offline
                                    E Offline
                                    Eytukan
                                    wrote on last edited by
                                    #22

                                    dighn wrote:

                                    How does stSourcePath.size==0 even compile?!

                                    #pragma warning (disable: 4786) In VC 6.0, it compiles.


                                    Best wishes to Rexx[^]

                                    1 Reply Last reply
                                    0
                                    • D dighn

                                      How does stSourcePath.size==0 even compile?! Also, is something wrong here: vec_stMovedFiles.push_back(&stDestPath); return; You are storing the address of a stack variable followed immediately by a return. The use of the variable must be after the return, at which point the variable is no longer valid.

                                      N Offline
                                      N Offline
                                      Nemanja Trifunovic
                                      wrote on last edited by
                                      #23

                                      dighn wrote:

                                      How does stSourcePath.size==0 even compile?!

                                      IIRC, VC++ 6.0 would let things like this compile.


                                      Programming Blog utf8-cpp

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups