On Mon, 10 Nov 2008 03:50:34 +0200, Timothy Madden
<te**********@gmail.comwrote in comp.lang.c:
[cross-posted to comp.lang.c, comp.lang.c++]
Hello
I see there is now why to truncate a file (in C or C++)
and that I have to use platform-specific functions for
truncating files.
If your platform has such functions.
Anyone knows why ? I mean C/C++ evolved over many years now,
and still, people making _the_ standards never decided to
include such a function. Even in POSIX it was included only
in recent versions, mostly not fully supported yet.
You seem to think that people making _the_ standards get to impose
their will by fiat.
Why is that ? They must think there is something wrong with it,
or that there are better ways to do it.
Or perhaps they think it is not generally useful enough.
I mean I want to write a portable application, I keep
application data in a file, at some point the user
deletes something from the data my program presents
to him/her, and now I delete some data from the data file
and want to shrink the file. Like a database system,
after dropping some records or tables and compacting
(or vacuum) the database. That is a good example
of when a programmer legally needs to truncate a file.
No, that is an example of when a programmer might want to truncate a
file.
Copying only remaining data to a new file that will then
replace the old one is not a solution for a large database,
and leaving the empty space in the file is also not a
solution for large files.
In your opinion, rewriting a file is "not a solution". I am sure that
others disagree. In fact, I think that there are many who would
disagree with compacting an existing file. Much too risky.
So why is it "not a solution"? For "large files", whatever your
definition of "large" is, I would suspect most programmers these days
would use a database engine. They are available for all popular
platforms, and even good, free open source versions are available. You
could use the database library to take care of details like this.
The simple fact is that it is not the language standard's job to add
every single function that some programmers might find useful. Once a
function is added to the standard library, every conforming
implementation needs to implement. Regardless of whether or not the
underlying operating system makes it easy.
There are many new language features or library functions that some
particular programmer thinks would make his/her job much easier, so
much so that it is worth the effort of every single compiler
implementer to add it to their compiler or library.
But no matter how useful such a function might be to you, there is a
cost/benefit calculation that need to be made.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html