Re: [dev] [lnanosmtp]

From: <>
Date: Sat, 11 Jun 2016 08:34:32 +0200

> I you pointed to a perfect example. While extremely it is extremely
> convenient for some architectures to represent strings as a pointer to
> char/bytes + an implicit terminator, Pascal strings (really, a
> struct/object containing pointer + length) are imminently safer. As

This is not true. Pascal strings are not safer. Pascal strings have
an advantage over C strings, you don't need to run over the string
to know the end of the string. BUT, Pascal strings have a lot of

        - Fixed maximum size. Pascal strings used a byte for the size,
          and it meant that you could not have strings bigger than 256.
          Of course you can increment this size to whatever you want,
          but then you waste a lot of space.
        - Strings are not idenpotent. In C strings, any pointer inside
          of the string is a new string. Splitting strings is only
          writing a 0. Splitting strings in Pascal strings require to
          allocate a new chunk of memory and copy all the characters.

In both strings you can mess everything if you access out of the limits,
so they have the same problem. C strings are very good if you run over
all the elements of the string and you want to do some operation over
them, but Pasacal strings are good if you want to do random operations
over the string, or operations at the end, for example concatenate.
As you can see, some operations are eassier in C strings, and other
are eassier in Pascal strings, and both are sfer equally if you don't
mistake. If you mistake you have the same problems in them.


PD: Pascal strings are not compossed of a size and a pointer, the first byte
of the string is the size, the characters are stored after this byte. Thus,
the space required for a C string and a Pascal string is the same.
Received on Sat Jun 11 2016 - 08:34:32 CEST

This archive was generated by hypermail 2.3.0 : Sat Jun 11 2016 - 08:36:11 CEST