Author Topic: Question about wx_str() and c_str()  (Read 7762 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Question about wx_str() and c_str()
« on: October 08, 2009, 02:50:05 am »
There are many code in the current trunk like below:

Code
            #if wxCHECK_VERSION(2, 9, 0)
                Manager::Get()->GetLogManager()->DebugLog(F(_T("Looking for type: '%s' (%d components)"), actual.wx_str(), type_components.size()));
            #else
                Manager::Get()->GetLogManager()->DebugLog(F(_T("Looking for type: '%s' (%d components)"), actual.c_str(), type_components.size()));
            #endif

After checking the wxWidgets header file(Windows)
D:\wxWidgets-2.8.10\include\wx\string.h

I find this statement:

Code
    const wxChar* wx_str()  const { return c_str(); }

So, I just manually change above code to below( remove the preprocessor  guard)
Code
                Manager::Get()->GetLogManager()->DebugLog(F(_T("Looking for type: '%s' (%d components)"), actual.wx_str(), type_components.size()));

It builds and works with no problem.

So, my question is: why not clean up these codes?
Thanks.



If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9702
Re: Question about wx_str() and c_str()
« Reply #1 on: October 08, 2009, 07:09:38 am »
Code
    const wxChar* wx_str()  const { return c_str(); }
This was added late to wxWidgets v2.8.10. If you remove the other option it'll break compilation of C::B on platforms where not the "latest" a.k.a v2.8.10 version of wxWidgets is available.

However, the cleanup will be done sooner or later...
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Question about wx_str() and c_str()
« Reply #2 on: October 08, 2009, 07:25:39 am »
Code
    const wxChar* wx_str()  const { return c_str(); }
This was added late to wxWidgets v2.8.10. If you remove the other option it'll break compilation of C::B on platforms where not the "latest" a.k.a v2.8.10 version of wxWidgets is available.

However, the cleanup will be done sooner or later...

I see, thanks!!
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7678
    • My Best Post
Re: Question about wx_str() and c_str()
« Reply #3 on: October 08, 2009, 02:12:55 pm »
Code
    const wxChar* wx_str()  const { return c_str(); }
This was added late to wxWidgets v2.8.10. If you remove the other option it'll break compilation of C::B on platforms where not the "latest" a.k.a v2.8.10 version of wxWidgets is available.

However, the cleanup will be done sooner or later...

I added the unneeded guard per an C::B dev request to get the patches applied.

The wx_str() has been in wxWidgets for years; but, it was obsoleted years ago.
Therefore, the was no wxWidgets docs saying it was safe to use.

From wxWidgets 2.8.0
Code
    // identical to c_str(), for wxWin 1.6x compatibility
    const wxChar* wx_str()  const { return c_str(); }

Tim S.


 
« Last Edit: October 08, 2009, 02:16:39 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Question about wx_str() and c_str()
« Reply #4 on: October 08, 2009, 02:25:11 pm »
I added the unneeded guard per an C::B dev request to get the patches applied.
:D
Sorry, I can't understand, what does this sentence mean?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7678
    • My Best Post
Re: Question about wx_str() and c_str()
« Reply #5 on: October 08, 2009, 02:51:41 pm »
I added the unneeded guard per an C::B dev request to get the patches applied.
:D
Sorry, I can't understand, what does this sentence mean?

The Code::Blocks person said add the guard (#ifdef/else/endif) and he would apply the patch.
http://forums.codeblocks.org/index.php/topic,10510.msg72130.html#msg72130
http://forums.codeblocks.org/index.php/topic,10510.msg72132.html#msg72132

I added the patch that was NOT needed. He applied the patch.

Tim S.
« Last Edit: October 08, 2009, 02:54:47 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6035
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Question about wx_str() and c_str()
« Reply #6 on: October 08, 2009, 03:36:50 pm »
I added the patch that was NOT needed. He applied the patch.
Tim S.

Ok,I know.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.