Fast and Safe C Strings: User friendly C macros to Declare and use C Strings. - Compilers
This is a discussion on Fast and Safe C Strings: User friendly C macros to Declare and use C Strings. - Compilers ; Some 20 years ago, it became clear that C strings were not as safe, nor
as fast, as strings in PL/I, Assembler or Pascal.
The primary reasons are that one needs to find the current length of a
string before ...
-
Fast and Safe C Strings: User friendly C macros to Declare and use C Strings.
Some 20 years ago, it became clear that C strings were not as safe, nor
as fast, as strings in PL/I, Assembler or Pascal.
The primary reasons are that one needs to find the current length of a
string before or during a copy process - this is very time consuming.
Secondly, there is no way of determining the maximum length of a string,
and therefore when copying to a string, it is easy to over-write
adjacent storage with often disastrous consequences, including the
deliberate introduction of viruses.
Decades have passed and the C string problem continues. Buffer
over-runs are just part of the story, and the bugs that can be
introduced - the safety problem is still with us all and it has come
back to bite all of us on the lower part of our anatomy, over and over
again.
I have spent some years studying this problem and have developed some
User friendly C macros that solve the problem.
These solutions do enhance the speed and safety aspects of all "C"
programs - these benefits of speed and safety can be passed on to your
users.
The main benefits are:
* Increased speed (up to 20 times for some string handling)
* More reliability (strings cannot overwrite adjacent storage)
* Easier coding and debugging (consistent set of macros)
* Easier external variables
Here is a very short example:
dcl (op,charvar,253," ",ext); // Variable 'op' is defined
// as an External variable - Max length of 253 characters.
dcl (symbolic,charfixed,8," ",ext); // Fixed length of 8
cpylit(op, "This is a 30 character string ");
cat(op,op); /* Concatenate variable op with it self. Now 60
characters */
cpy(symbolic,op); /* Truncates it to 8 characters */
cpy(op,symbolic); /* Copy it back. */
I invite you download the macros and code at
http://members.ozemail.com.au/~oscar.../fastsafe.html where a fuller
discussion can be found.
Clement Clarke
,-._|\ Clement V. Clarke - Author Jol, EASYPANEL, OSCAR, 370TO486
/ Oz \ Web: www.ozemail.com.au/~oscarptyltd
\_,--.x/ 38 Kings Park Road, West Perth, AUSTRALIA, 6005.
v Tel (61)-8-9324-1119, Mob 0401-054-155.
[These look somewhat like Dan Bernstein's string library that he wrote
ten years ago, except without the dynamic allocation. -John]
-
Re: Fast and Safe C Strings: User friendly C macros to Declare and use C Strings.
Clem Clarke wrote:
> Some 20 years ago, it became clear that C strings were not as safe, nor
> as fast, as strings in PL/I, Assembler or Pascal.
Readers may be interested in the discussion that this post provoked
on comp.lang.c. (It did not receive universal acclaim.)
--
"We are on the brink of a new era, if only --" /The Beiderbeck Affair/
Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN
Similar Threads
-
By Application Development in forum c++
Replies: 7
Last Post: 10-19-2007, 07:54 PM
-
By Application Development in forum Python
Replies: 4
Last Post: 08-23-2007, 05:20 AM
-
By Application Development in forum Theory
Replies: 1
Last Post: 06-14-2007, 08:21 PM
-
By Application Development in forum DOTNET
Replies: 5
Last Post: 09-06-2005, 02:50 AM
-
By Application Development in forum Perl
Replies: 2
Last Post: 05-06-2005, 09:26 PM