Re: [Flightgear-devel] sprintf

2005-07-26 Thread Erik Hofman

Jon Berndt wrote:

IIRC, sprintf was a problem for some. Is that still the case? I've compiled 
under Cygwin,
Borland C++, and I think I've also compiled code that uses sprintf under IRIX.


The real problem was snprintf(...) which isn't availble under Winodws:

#if defined(_WIN32)  !defined(__CYGWIN__)
  #define snprintf _snprintf
#endif


Erik

___
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d


Re: [Flightgear-devel] sprintf

2005-07-26 Thread Christian Mayer
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Erik Hofman schrieb:
 Jon Berndt wrote:
 
 IIRC, sprintf was a problem for some. Is that still the case? I've
 compiled under Cygwin,
 Borland C++, and I think I've also compiled code that uses sprintf
 under IRIX.
 

sprintf is C standard - and very unsafe due to possible buffer
overflows. It shouldn't be used.

The inofficial (i.e. there's no standard yet AFAIK) C solution is snprintf:

 The real problem was snprintf(...) which isn't availble under Winodws:
 
 #if defined(_WIN32)  !defined(__CYGWIN__)
   #define snprintf _snprintf
 #endif

The real cross platform soultion would be the C++ std::string


CU,
Chris
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFC5fY9lhWtxOxWNFcRAn5KAJ4/ymkStSRQcOrUbIUpqdRy6D11rACgsHYs
iveF3b6qmM5Yz393cHfX5gs=
=q0Yi
-END PGP SIGNATURE-

___
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d


Re: [Flightgear-devel] sprintf

2005-07-26 Thread Erik Hofman

Christian Mayer wrote:


The real cross platform soultion would be the C++ std::string


No, you can't format (the f in printf) the string using the default C++ 
string class).


Erik


___
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d


Re: [Flightgear-devel] sprintf

2005-07-26 Thread Christian Mayer
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Erik Hofman schrieb:
 Christian Mayer wrote:
 
 The real cross platform soultion would be the C++ std::string
 
 
 No, you can't format (the f in printf) the string using the default C++
 string class).

You have to use the I/O manipulators (Stroustrup: 21.4.6.2, page 633ff.)
like std::setprecision().

Compared to the fast printf syntax they are too annoying to write and
not that flexible, but they are more readable and they can be combined
to your own user defined I/O manipulators. So you can write easily very
readable code without the need to retype everything.

CU,
Chris


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFC5gE/lhWtxOxWNFcRAguhAKCmz+gYRTu9b+vBoJuLNDm6VJs+rQCfSznC
v0iykSBU97YqOiobZru7qFE=
=eMKQ
-END PGP SIGNATURE-

___
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d


RE: [Flightgear-devel] sprintf

2005-07-26 Thread Jon Berndt
  No, you can't format (the f in printf) the string using the default C++
  string class).

 You have to use the I/O manipulators (Stroustrup: 21.4.6.2, page 633ff.)
 like std::setprecision().

The string class cannot create a string representation of a floating point 
number as far
as I can tell. The next best thing (IMHO) is sprintf().

I wish we could do this:

string myString=
double myValue=3.1415;

myString = The value of pi is:  + string(myValue) + \n;

I've had enough trouble with stringstreams that I don't want to go that path.

Jon


___
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d


Re: [Flightgear-devel] sprintf

2005-07-26 Thread Andy Ross
Christian Mayer wrote:
 You have to use the I/O manipulators (Stroustrup: 21.4.6.2, page 633ff.)
 like std::setprecision().

 Compared to the fast printf syntax they are too annoying to write and
 not that flexible, but they are more readable and they can be combined
 to your own user defined I/O manipulators. So you can write easily very
 readable code without the need to retype everything.

Just to add fuel to the fire, I will point out that this is a
theoretical result.  I've never once seen a complex iostream usage
that I considered readable.

Formatting text is a solved problem; programmers know what they want,
and they want printf.  C++ tried to get fancy, and failed.  Much of
the same can be said for the STL; 90% of developers are never going to
care about pluggable algorithms, but 100% of them want a simple hash
table.  Guess which they got?

Andy

___
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d