• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
String to number conversions with gcc 4.2.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

String to number conversions with gcc 4.2.


  • Subject: String to number conversions with gcc 4.2.
  • From: Robert Bell <email@hidden>
  • Date: Thu, 03 Sep 2009 10:21:41 -0700


Hi all,

I noticed some different behaviour with release vs. debug mode when using istringstream. Not sure if it is something I am doing, but too make sure  I grabbed the "standard" example from http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2.

It's probably something else I am doing that is stupid in the new environment, but it looks like in debug mode, an exception is being thrown in:

template<typename _Facet>
    inline const _Facet&
    __check_facet(const _Facet* __f)
    {
      if (!__f)
__throw_bad_cast();
      return *__f;
    }

Here is what I put into a simple command line too using c++ stdc++:

------

#include <iostream>
#include <sstream>
#include <string>
#include <stdexcept>


class BadConversion : public std::runtime_error{
public:
BadConversion(const std::string& s)
: std::runtime_error(s)
{ }
};

inline double convertToDouble(const std::string& s)
{
std::istringstream i(s);
double x;
if (!(i >> x))
throw BadConversion("convertToDouble(\"" + s + "\")");
return x;
}


int main (int argc, char * const argv[]){
double d = 0.0;
std::string s = "9877.0";
d = convertToDouble(s);
std::cout << "d: " << d << std::endl;
    return 0;
}

------

Here is the output in the different modes (release and debug). I turned off stopping on exception throw to let it fall through.

------

[Session started at 2009-09-03 10:07:15 -0700.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1344) (Fri Jul  3 01:19:56 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys002
Loading program into debugger…
Program loaded.
run
[Switching to process 4968]
Running…
d: 9877

Debugger stopped.
Program exited with status value:0.
[Session started at 2009-09-03 10:08:17 -0700.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1344) (Fri Jul  3 01:19:56 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys003
Loading program into debugger…
sharedlibrary apply-load-rules all
Program loaded.
run
[Switching to process 4983]
Running…
terminate called after throwing an instance of 'BadConversion'
  what():  convertToDouble("9877.0")
Program received signal:  “SIGABRT”.
(gdb)

------

Thanks,

Robert.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • g++-4.0 vs g++-4.2 debug exceptions.
      • From: Robert Bell <email@hidden>
  • Prev by Date: Re: How to file a bug in Rez tool for Intel processor?
  • Next by Date: Warnings and Errors columns empty
  • Previous by thread: Re: Java project creation in Xcode 3.2
  • Next by thread: g++-4.0 vs g++-4.2 debug exceptions.
  • Index(es):
    • Date
    • Thread