Article View: comp.lang.c++.leda
Article #4Re: STRING_CONSTRUCTOR limits strings to 512 byte
From: David F. Skoll
Date: Mon, 31 Jul 1995 17:45
Date: Mon, 31 Jul 1995 17:45
39 lines
1896 bytes
1896 bytes
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.
Technical Details
Message-ID:
<DCLDB9.ArI@cunews.carleton.ca>Path:
arc1-ca.pugleaf.net!howland.reston.ans.net!torn!nott!cunews!dfsReferences:
<3viuuv$dcl@news.rwth-aachen.de>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.c++.leda Path: arc1-ca.pugleaf.net!howland.reston.ans.net!torn!nott!cunews!dfs From: dfs@doe.carleton.ca (David F. Skoll) Subject: Re: STRING_CONSTRUCTOR limits strings to 512 byte X-Nntp-Posting-Host: doegate.doe.carleton.ca Message-ID: <DCLDB9.ArI@cunews.carleton.ca> Sender: news@cunews.carleton.ca (News Administrator) Organization: Carleton University X-Newsreader: TIN [version 1.2 PL2] References: <3viuuv$dcl@news.rwth-aachen.de> Date: Mon, 31 Jul 1995 17:45:09 GMT