Article View: comp.lang.c++.leda
Article #18Re: STRING_CONSTRUCTOR limits strings to 512 byte
From: R. van der Wal
Date: Thu, 03 Aug 1995 12:34
Date: Thu, 03 Aug 1995 12:34
50 lines
2396 bytes
2396 bytes
In article <DCLDB9.ArI@cunews.carleton.ca> dfs@doe.carleton.ca (David F. Skoll) writes:
>From: dfs@doe.carleton.ca (David F. Skoll)
>Subject: Re: STRING_CONSTRUCTOR limits strings to 512 byte
>Date: Mon, 31 Jul 1995 17:45:09 GMT
>In article <3viuuv$dcl@news.rwth-aachen.de>, Peter Haumer
>(haumer@informatik.rwth-aachen.de) wrote:
>> The macro STRING_CONSTRUCTOR in _string.c limits the size of strings to
>> 512 bytes. I don't think that this is necessary. Does anybody know, why it
>> is is implemenented in this way?
>Because it's implemented incorrectly. Even worse, "512" is hard-coded.
>It should be a macro, at least.
>> There should be at least an assertion for a precondition or a size check
>> in the macro. Programs which want to construct longer strings with varargs
>> just crash/core dump.
>The only *portable* way (other than writing one's on sprintf-like
>function) to handle very long strings is to write them to a file (with
>vfprintf...) and then read the file back into memory. The
>sprintf... functions have no provisions for checking buffer overflow,
>which makes checking the precondition very difficult.
>A nicer solution, IMO, is for LEDA authors to define left-shift
>operators like this:
>string & string::operator<<(int i) { ... }
>string & string::operator<<(double d) { ... }
>etc...
>Then you could say:
>string s;
>int a=4, b=6;
>s << a << " times " << b << " equals " << a*b;
>which would append to s. This is type-safe and more "C++-like".
>--
>David F. Skoll
><a HREF="http://www.doe.carleton.ca/students/dfs/">
>Click here for my home page</a> "Query two pi" on typewriter.
The latter suggestion is actually implemented in classes strstream and
ostrstream. Being part of the C++ standard library, they are probably
preferable to building your own string extensions for this purpose.
Ron van der Wal.
Technical Details
Message-ID:
<R.vanderWal.4.3020C23B@KE.rulimburg.nl>Path:
arc1-ca.pugleaf.net!ke0025.rulimburg.nl!R.vanderWalReferences:
<3viuuv$dcl@news.rwth-aachen.de> <DCLDB9.ArI@cunews.carleton.ca>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!ke0025.rulimburg.nl!R.vanderWal From: R.vanderWal@KE.rulimburg.nl (R. van der Wal) Newsgroups: comp.lang.c++.leda Subject: Re: STRING_CONSTRUCTOR limits strings to 512 byte Date: Thu, 3 Aug 1995 12:34:03 GMT Organization: Rijksuniversiteit Limburg Message-ID: <R.vanderWal.4.3020C23B@KE.rulimburg.nl> References: <3viuuv$dcl@news.rwth-aachen.de> <DCLDB9.ArI@cunews.carleton.ca> NNTP-Posting-Host: ke0025.rulimburg.nl X-Newsreader: Trumpet for Windows [Version 1.0 Rev A]